Page 1 of 2

Stopping walk animation/Laggy Map?

Posted: Thu Nov 04, 2010 11:50 pm
by Ryne
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.

Code: Select all

  	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!

Re: Stopping walk animation?

Posted: Fri Nov 05, 2010 1:10 am
by TechnoCat
You need to set the animation if none of those are pressed.
Ryne wrote:

Code: Select all

 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

Code: Select all

 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!

Re: Stopping walk animation?

Posted: Fri Nov 05, 2010 1:37 am
by Ryne
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?

Good
http://dl.dropbox.com/u/7905642/good.love

Bad
http://dl.dropbox.com/u/7905642/bad.love

Re: Stopping walk animation/Laggy Map?

Posted: Fri Nov 05, 2010 7:13 am
by Robin
Both error --- you need to pass a size to NewFont, or it won't work.

Also, use elseif instead of else if. You wrote this:

Code: Select all

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
where you could have written:

Code: Select all

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

Re: Stopping walk animation/Laggy Map?

Posted: Fri Nov 05, 2010 12:14 pm
by TechnoCat
Robin wrote:Both error --- you need to pass a size to NewFont, or it won't work.
Pretty sure it errors because we are on an outdated build of 0.7.0.
Also, I fixed the "else if"s to "elseif"s in my previous post. Oops.

Re: Stopping walk animation/Laggy Map?

Posted: Fri Nov 05, 2010 7:27 pm
by Ryne
Robin wrote:Both error --- you need to pass a size to NewFont, or it won't work.

Also, use elseif instead of else if. You wrote this:

Code: Select all

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
where you could have written:

Code: Select all

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?

Re: Stopping walk animation/Laggy Map?

Posted: Fri Nov 05, 2010 8:10 pm
by bartbes
There's no diff here, so I'm afraid I can't help.

Re: Stopping walk animation/Laggy Map?

Posted: Fri Nov 05, 2010 8:11 pm
by Robin
I see it lag, but no clue as to how that happens.

What is draw_map() supposed to do (apart from, you know, drawing the map)?

Re: Stopping walk animation/Laggy Map?

Posted: Fri Nov 05, 2010 8:47 pm
by bartbes
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.

Re: Stopping walk animation/Laggy Map?

Posted: Fri Nov 05, 2010 9:58 pm
by Ryne
Robin wrote:I see it lag, but no clue as to how that happens.

What is draw_map() supposed to do (apart from, you know, drawing the map)?
Im not certain if it's doing anything else or not, I used the code from the fine tile based tutorial http://love2d.org/wiki/Tutorial:Fine_Ti ... _Scrolling