Hello everyone! I'm wondering how I could have multiple animations? Like an idle, walking, running, etc. The problem is that when I run (which is the else) It goes through the whole animation sheet, I know why but have no clue how to tackle.
Responses much appreciated!
-- player anim if not pl.wlk then if pl.sp <= 4 then pl.sp+=0.01 else pl.sp=1 end else if pl.sp <= 6.9 then pl.sp+=0.1 else pl.sp=5 end end |
![](/gfx/set_like0.png)
![](/gfx/top_drop.png)
![](/media/85395/picocolordance_24.gif)
anim_walk={1,2,3,4} anim_run={5,6,7,8} function getanimframe(anim,fps) return anim[1+flr(fps*t()%#anim)] end --usage if (player.isrunning) player.sprite=getanimframe(anim_run,15) |
fps
is the frames/sec you want the animation to appear to run at. Note that the frame is dependent on the current runtime of the game overall and not when the animation was set. You can add some more to this to implement a time offset to ensure you always start off on the first frame but that's a bit more complicated.
Instead, I like to use this in conjunction with a second anim system that handles "one-shot" anims separately (jumping, attack moves). But I'm on my phone and don't have that code handy or memorized. I may be able to get back to this in the morning and add that.
Good luck!
[Please log in to post a comment]