Log In  

As mentioned in another thread, I had this bug while testing tline().

Notice that I use ctrl+click to swap c1 to c2, but some pixels are not changed.

I used a lot of commands and tools while doing it the first time, so it's hard to know what triggered it (1 and 2 to navigate between colors, V and F to flip, Ctrl+click to swap colors, ctrl+C, ctrl+V, copied sprites to map). I didn't use the new shape tool.

I tried to reproduce the bug with many combinations of the mentioned commands and tools with no success.

Here is a Ctlr+Y of the steps that introduced the bug (no bugs prior to that).

Notice that the grey pixels that only appear when running the cart aren't on the same pixels I drew, but 1 pixel to the right.

After that, I saved the card for the Nth time, but for some reason, I couldn't undo anything before saving the file. And the color bug also disappeared. Maybe the color bug has to do with something wrong with the Undo/Redo chain..?

P#76829 2020-05-18 13:20 ( Edited 2020-05-29 23:01)

ooh nice rotating sprite!

is possible to get the code for that?

P#77331 2020-05-28 20:15
1

@Munro Sure, here it is.

function rspr(sx,sy,sw,sh,dx,dy,a,f)
--[[
sx,sy,dx,dy are center,
not corner
]]
 f=f and -1 or 1
 a=a*f
 a=a+.25
 for i=-sh,sh do
  tline
  (
  dx-sh*f,dy+i,
  dx+sh*f,dy+i,
  (sin(a)*sw/8+cos(a)*(i)/8)+sx/8,
  (cos(a)*sw/8-sin(a)*(i)/8)+sy/8,
  -sin(a)/8,-cos(a)/8,
  1
  )
 end
end

SX, SY, SW, SH, DX, DY as seen in SSPR.
SX, SY, DX, DY are for the center of the sprite, not the corner like in other draw functions, and also determine the center of rotation.
SW and SH count in both directions from the center, so it's essentially doubled.

A is angle.

F is flip.

Notice that the last line argument is 1, so you have to set the sprite flags accordingly (or change/remove this argument).
In case you're not familiar with tline, the images are picked from the map, not the sprite area, so this function uses the map too, not sprites.

P#77371 2020-05-29 13:27
1

I'd recommend an optimization here, of pulling the trig and divisions out of the for loop. It should give you much better performance. :)

function rspr(sx,sy,sw,sh,dx,dy,a,f)
 f=f and -1 or 1
 a*=f
 a+=.25
 local sina8 = sin(a)>>3 --equivalent to sin(a)/8, but faster
 local cosa8 = cos(a)>>3
 sx>>=3 --since only used as sx/8 in loop, might as well change these variables as well
 sy>>=3
 for i=-sh,sh do
  tline(dx-sh*f,dy+i,dx+sh*f,dy+i,
   sw*sina8+i*cosa8+sx,
   sw*cosa8-i*sina8+sy,
   -sina8,-cosa8,1)
 end
end
P#77382 2020-05-29 15:18 ( Edited 2020-05-29 15:31)
1

very nice, thank for the explanation and code!

P#77383 2020-05-29 15:23

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 07:08:17 | 0.018s | Q:17