Log In  

So I've created this code to make walking animations:

if plr.walking then
  if time()-plr.anim>.1 then
   plr.anim=time()
   plr.sp+=1
   if plr.sp>5 then
    plr.sp=2

also added this for idle sprite:

if not plr.walking then
 plr.sp=1

However I can't figure out a way to change the sprite to the upward/downward movement sprites (spr 6-9, sprite 10-13) without having the code overwirte the plr.sp eachframe

if plr.upmove then
 plr.sp=6
 #Do anim function

as far as I've gotten is making the sprite change to the correct movement sprite and then have it iterate back to the idle animation or animate to the very next frame and revert back to the first forward sprite

P#106452 2022-02-06 19:10

If you never increase plr.sp by more than 1 and have all your other the animation frames be sequential, then it should work to check which sprite number plr.sp is equal to rather than above. You'd just need to do that as a replacement for incrementing rather than doing it afterward.

if plr.walking then
  if time()-plr.anim>.1 then
   plr.anim=time()
   if plr.sp==5 then
    plr.sp=2
   elseif plr.sp==9 then
    plr.sp=6
   elseif plr.sp==13 then
    plr.sp=10
   else
    plr.sp+=1
   end
P#106459 2022-02-06 20:45

The sprites now change to the first animation of movement, yet upwards only advances two sprites and downward advances one sprite.

if not plr.walking then
        plr.sp=1
    end

    if plr.upmove then
  plr.sp=6
 end

 if plr.downmove then
  plr.sp=10
 end

#Anim function with increment checks

tried changing the anim increment to plr.anim>.20 and doesnt increase the sprites anims

P#106529 2022-02-08 01:52

The code you posted checks if the player is not walking. If so, it sets the sprite to 1. Then, separately, it checks if the player is moving up and if so sets the sprite to 6. Then, separately, it does so for moving down.

If you want the check for not walking to apply to all three, this is how it should be written:

if not plr.walking then
        plr.sp=1
    if plr.upmove then
  plr.sp=6
 end

 if plr.downmove then
  plr.sp=10
 end
end
P#106530 2022-02-08 02:01

the problem isnt that, the problem is that it checks if plr.upmove/plr.downmove and changes the sprite every frame, which is why walking left or right is able to cycle thru the animation frames without a hitch.

Might have to mess around with the draw_player function to get this going

P#106532 2022-02-08 02:26

[Please log in to post a comment]