Hi again!, I have my sprites and animations created but I can't get the animation to stop after releasing the button. I've tried a few different things and nothing has worked. Heres the code that I have for walking in multiple directions (these were all separate "If" statements before I combined them to test a theory, I wasnt sure if It was better to leave them separate or keep them all in the same statement.
if love.keyboard.isDown( "w" ) then
state = animup
player.y = player.y - 1
else if love.keyboard.isDown( "s" ) then
state = animdown
player.y = player.y + 1
else if love.keyboard.isDown( "d" ) then
state = animright
player.x = player.x + 1
else if love.keyboard.isDown( "a" ) then
state = animleft
player.x = player.x - 1
end
end
end
end
Basically I can walk in any direction, and the animations play correctly but I just want the player to stop walking after releasing the key. I figured I would need a "Standing" sprite for each direction, I just don't know how to implement. Any help would be appreciated, Thanks!
Last edited by Ryne on Fri Nov 05, 2010 3:20 am, edited 1 time in total.
if love.keyboard.isDown( "w" ) then
state = animup
player.y = player.y - 1
else if love.keyboard.isDown( "s" ) then
state = animdown
player.y = player.y + 1
else if love.keyboard.isDown( "d" ) then
state = animright
player.x = player.x + 1
else if love.keyboard.isDown( "a" ) then
state = animleft
player.x = player.x - 1
end
end
end
end
(I took the liberty of restructuring what you wrote, the ends didn't match up otherwise.)
What I propose
state = animstand
if love.keyboard.isDown( "w" ) then
state = animup
player.y = player.y - 1*dt
elseif love.keyboard.isDown( "s" ) then
state = animdown
player.y = player.y + 1*dt
elseif love.keyboard.isDown( "d" ) then
state = animright
player.x = player.x + 1*dt
elseif love.keyboard.isDown( "a" ) then
state = animleft
player.x = player.x - 1*dt
end
This way, animstand only gets overwritten if you do press a button, otherwise it persists.
AND DON'T FORGET YOUR DT's!
Last edited by TechnoCat on Fri Nov 05, 2010 12:12 pm, edited 1 time in total.
Thanks, I appreciate the help! I NOW seem to be having a strange issue where if my "map" isn't drawn the game becomes choppy, or at least the character does. I uploaded these 2 examples use WASD to move, notice the "Good.love" animation is smooth and the "Bad.love" isn't? The only difference is that draw_map() is omitted from the game draw. Any Idea why it gets choppy when it isn't drawn?
if love.keyboard.isDown( "w" ) then
state = animup
player.y = player.y - 1
else
if love.keyboard.isDown( "s" ) then
state = animdown
player.y = player.y + 1
else
if love.keyboard.isDown( "d" ) then
state = animright
player.x = player.x + 1
else
if love.keyboard.isDown( "a" ) then
state = animleft
player.x = player.x - 1
end
end
end
end
if love.keyboard.isDown( "w" ) then
state = animup
player.y = player.y - 1
elseif love.keyboard.isDown( "s" ) then
state = animdown
player.y = player.y + 1
elseif love.keyboard.isDown( "d" ) then
state = animright
player.x = player.x + 1
elseif love.keyboard.isDown( "a" ) then
state = animleft
player.x = player.x - 1
end
if love.keyboard.isDown( "w" ) then
state = animup
player.y = player.y - 1
else
if love.keyboard.isDown( "s" ) then
state = animdown
player.y = player.y + 1
else
if love.keyboard.isDown( "d" ) then
state = animright
player.x = player.x + 1
else
if love.keyboard.isDown( "a" ) then
state = animleft
player.x = player.x - 1
end
end
end
end
if love.keyboard.isDown( "w" ) then
state = animup
player.y = player.y - 1
elseif love.keyboard.isDown( "s" ) then
state = animdown
player.y = player.y + 1
elseif love.keyboard.isDown( "d" ) then
state = animright
player.x = player.x + 1
elseif love.keyboard.isDown( "a" ) then
state = animleft
player.x = player.x - 1
end
Ive actually fixed the "elseif" issues since the first post, though fixing the font doesn't fix the game lagging when the map isn't drawn. In the "bad.love" example the player is choppy when yo move him around, in the "good.love" its perfectly smooth. The only difference being that draw_map() is excluded from the "bad.love" Any ideas?
I'm guessing it's not the draw_map function that directly prevents the lag/choppiness/whatever, but it's actually slowing down the rest, thereby somehow preventing the aforementioned lag.