hi all,
i'm new to pico8 and coding largely, and i'd appreciate some help. i'm working on a super simple file just to familiarize myself with different aspects of what i'd like to eventually make for real.
what i'm trying to do is cause a specific set of sprites to animate whenever the player presses btn(4).
so far, i've got it set up so that when the player presses z, the function draw_attack() is called (below).
the problem i'm running into is that the animation ceases after one frame. i have no idea why. here's my code that seems to be the problem:
function draw_attack() if player.flip then spr(atkanim.spr,player.x-6,player.y) for i=0,3 do if atkanim.spr<=52 then atkanim.spr+=0.5 sfx(0) else atkanim.spr=48 end end else spr(48,player.x+6,player.y) sfx(0) end end |
what i would expect to happen with this when the function is called: the sprites are drawn in sequence based on the for loop.
what actually happens: the first frame of the sequence appears in the right place, and the sound effect works, and then the sprite disappears.
if i spam the key that calls the function, the sprite seems to cycle through the set of sprites i've defined but only appearing while the key is pressed for 1 frame each time. does this make sense?
i realize there are simpler ways to animate but i haven't really found a tutorial that i can follow... i'd appreciate if anyone is willing to help me wrap my head around this. thanks!
that function draws the sprite once, then runs through the for loop changing a variable in 0.5 increments while playing a sound each time and drawing nothing. edit:assuming the player is facing the correct direction, of course
In case the info helps you notice what's going on: there's no such thing as a sprite "object" that does or means anything. spr() is just a handy way to draw a chunk of pixels to the screen.
[Please log in to post a comment]