I'm making a circle grow by simply increasing its radius. However, I want it to grow slower than +1 per frame. I'm doing this now by making a counter var for the circle, checking it against a frame timer and then moving on. I end up using this method a lot for various things and that makes me believe there is a better way.
This method clearly works but is there some sort of shorthand or anything I can do to get the same result?
circle={x=64,y=64,r=1,t=0,f=3} function _update() if circle.t>=circle.f then circle.r+=1 circle.t=0 end circle.t+=1 end function _draw() circ(circle.x, circle.y, circle.r, 10) end |
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
Try just incrementing by less than 1! The draw functions generally deal when you throw them non-integers. There are cases where it can yield jitter or unevenness, but then you just drop in a flr().
circle={x=64,y=64,r=1,t=0,f=3} function _update() circle.r+=0.2 end function _draw() circ(circle.x, circle.y, circle.r, 10) end |
edit: insert caveat about habits and strongly typed languages or something along those lines
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
Good point. Didn't really think about that...guess in my brain the P8 just deals with integers since that's how the pixels end up working but you're right. I'll give it a shot. Thanks!
[Please log in to post a comment]