snakes_wayne [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=46337 Help with simple animation <p>hi all,</p> <p>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.</p> <p>what i'm trying to do is cause a specific set of sprites to animate whenever the player presses btn(4).</p> <p>so far, i've got it set up so that when the player presses z, the function draw_attack() is called (below).</p> <p>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:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> function draw_attack() if player.flip then spr(atkanim.spr,player.x-6,player.y) for i=0,3 do if atkanim.spr&lt;=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 </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>what i would expect to happen with this when the function is called: the sprites are drawn in sequence based on the for loop.</p> <p>what actually happens: the first frame of the sequence appears in the right place, and the sound effect works, and then the sprite disappears.</p> <p>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?</p> <p>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!</p> https://www.lexaloffle.com/bbs/?tid=39129 https://www.lexaloffle.com/bbs/?tid=39129 Thu, 06 Aug 2020 21:43:58 UTC