Stopping walk animation/Laggy Map?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Stopping walk animation/Laggy Map?

Post 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!
Last edited by Ryne on Fri Nov 05, 2010 3:20 am, edited 1 time in total.
@rynesaur
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Stopping walk animation?

Post 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!
Last edited by TechnoCat on Fri Nov 05, 2010 12:12 pm, edited 1 time in total.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Stopping walk animation?

Post 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
@rynesaur
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Stopping walk animation/Laggy Map?

Post 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
Help us help you: attach a .love.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Stopping walk animation/Laggy Map?

Post 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.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Stopping walk animation/Laggy Map?

Post 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?
@rynesaur
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Stopping walk animation/Laggy Map?

Post by bartbes »

There's no diff here, so I'm afraid I can't help.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Stopping walk animation/Laggy Map?

Post 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)?
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Stopping walk animation/Laggy Map?

Post 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.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Stopping walk animation/Laggy Map?

Post 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
@rynesaur
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 1 guest