Log In

 1

My code for sprite rotation:

 ```function sprrot(id,x,y,a,s) id=flr(id) function getcol(px,py) return ((px<1 and py<1)and(px>=0 and py>=0)) and sget((px*8)+((id%16)*8),(py*8)+(flr(id/16)*8)) or -1 end for py=0,s*13 do --floor(9*sqrt(2)) for px=0,s*13 do local uv={x=((px/(11*s))-.6),y=((py/(11*s))-.6)} local col=getcol(((uv.x*cos(a))-(uv.y*sin(a)))+.5,((uv.x*sin(a))+(uv.y*cos(a)))+.5) if(col>0)then pset(flr(x+(px-(6.36*s))),flr(y+(py-(6.36*s))),col) end end end end ```

Any better ones?

P#26724 2016-08-10 05:58 ( Edited 2016-08-13 20:01)

at a glance, there's a lot of calculation you should move away from the loops:

• cos(a) & sin(a) are constant throughout the whole function. just have cs=cos(a) sn=sin(a) at the very start, then use cs & sn. right now there are 1313ss4 calls to those functions when you only need 2.
• ((py/(11s))-.6) and flr(y+(py-(6.36s))) do not depend on px, so they are constant in the px loop, calculate them beforehand.

hope that helps :)

P#26726 2016-08-10 08:02 ( Edited 2016-08-10 15:51)
P#26863 2016-08-13 16:01 ( Edited 2016-08-13 20:01)

[Please log in to post a comment]

Follow Lexaloffle:
Generated 2022-12-10 01:29:37 | 0.005s | Q:9