how to put an animation only when i jump?
is there a way to add animation only when jumping?
I have to put the jump animation in place of the normal walking animation
is there a way to add animation only when jumping?
I have to put the jump animation in place of the normal walking animation
I would keep a value that keeps track of how long the player has been in the air. If this value is 0, there is no need to use the jumping animation, and if it isn't, you can also use the value to cycle through jump frames. Something like this:
update = function()
if on_floor() then // on_floor() must be defined of course
airtime = 0
else
airtime += 1
end
if airtime > 0 then
// here you would cycle through a jumping animation
else
// here you would use your normal code for a walking animation
end
end
Just check if you are jumping (I'll do the same as @this_name_is_taken and name it on_floor() for the example) and if so, do jumping animation
draw = function()
if on_floor()
screen.drawSprite("walking", x, y, 20, 20)
else
screen.drawSprite("jumping", x, y, 20, 20)
end
end
That's a bit more complicated, as a floor check depends on what kind of project you have (and how you calculate collision). There are a number of examples in the explore section of how you can do this, but the only real way that me or @JmeJuniper can help you directly is with more information about your project.
If you are making a platformer then you can also check the players y velocity(If you have one)
if player.vy > 0 then
//do the jumping anim
elsif player.vy < 0 then
// do the falling anim
end
This is how I do it cuz it allows a falling animation and it generaly works good.
I personally adjust onFloor
when checking for collisions (There are many ways to do this, so it really depends on your project, but generally you check if a player's x & y collide with any walls and then repel the player until they are no longer touching that wall):
if floor_collision then
collision_handler()
onFloor = true
else
onFloor = false
end
If you want a separate jumping and falling animation, you can do what @MrBoi said (but check for onFloor too!), I just don't like using that alone, because ramps don't work well with it and maybe you want ramps or something else, this is more versatile.