Animating

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.
Post Reply
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Animating

Post by Kasperelo »

Please help me! I'm not sure what's wrong with the animation.
Last edited by Kasperelo on Sun May 20, 2012 1:33 pm, edited 1 time in total.
User avatar
IMP1
Prole
Posts: 43
Joined: Mon Oct 03, 2011 8:46 pm

Re: Animating

Post by IMP1 »

I think it may be the line(s) in 'player.lua':

Code: Select all

player.iterator = player.iterator + dt
That's not adding a whole number, but player.iterator (I think) has to be an integer. Try adding 'love.graphics.print(player.iterator, 0, 0) to your draw function so you can see what the variable is.

Add another varaible, call it animationTimer or something, and add dt to it every frame. Then if animationTimer >= [however long you wait between animation frames], then add one to player.iterator, and subtract dt from animationTimer.

Or use an animation library/class. I'm sure there are lots out there.
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Animating

Post by Kasperelo »

OK!
I'll try
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Animating

Post by Kasperelo »

Hm. Kinda works, but for some reason one of the frames doesn't show up?
Last edited by Kasperelo on Sun May 20, 2012 1:33 pm, edited 1 time in total.
User avatar
juno
Citizen
Posts: 85
Joined: Thu May 10, 2012 4:32 pm
Location: London

Re: Animating

Post by juno »

You're trying to access a table value (playerQuads.down, playerQuads.up..) with a string value.
One way to solve this is to create an empty table - playerQuads = { }, create the 4 quad animations as separate tables and then add them to playerQuads so that playerQuads[1] is down, playerQuads[2] is up etc. This means you need to change your player.direction value to an integer 1-4 instead of strings.

Here, I made a few changes to your player

Code: Select all

	control = {
		up = "w",
		down = "s",
		left = "a",
		right = "d",
		attack = "l"
	}
	
	player = {
		x = 600,
		y = 325,
		speed = 200,
		sprite = love.graphics.newImage("pics/quads/player.png"),
		direction = 1,
		iterator = 1
	}
	
	local playerQuads={}
	
	local downQuad = {
			love.graphics.newQuad(0, 0, 24, 63, 96, 252),
			love.graphics.newQuad(0, 63, 24, 63, 96, 252),
			love.graphics.newQuad(0, 126, 24, 63, 96, 252),
			love.graphics.newQuad(0, 189, 24, 63, 96, 252)
		}
	local upQuad = {
		love.graphics.newQuad(24, 0, 24, 63, 96, 252),
		love.graphics.newQuad(24, 63, 24, 63, 96, 252),
		love.graphics.newQuad(24, 126, 24, 63, 96, 252),
		love.graphics.newQuad(24, 189, 24, 63, 96, 252)
	} 
	local rightQuad = {
		love.graphics.newQuad(48, 0, 24, 63, 96, 252),
			love.graphics.newQuad(48, 63, 24, 63, 96, 252),
			love.graphics.newQuad(48, 126, 24, 63, 96, 252),
			love.graphics.newQuad(48, 189, 24, 63, 96, 252)
	} 
	local leftQuad = {
		love.graphics.newQuad(72, 0, 24, 63, 96, 252),
			love.graphics.newQuad(72, 63, 24, 63, 96, 252),
			love.graphics.newQuad(72, 126, 24, 63, 96, 252),
			love.graphics.newQuad(72, 189, 24, 63, 96, 252)
	} 

table.insert(playerQuads, downQuad)--1
table.insert(playerQuads, upQuad)--2
table.insert(playerQuads, rightQuad)--3
table.insert(playerQuads, leftQuad)--4

function playerDraw()

	if gamestate == "playing" then
		love.graphics.drawq(player.sprite, playerQuads[player.direction][player.iterator], player.x, player.y)
	end
	
end

function playerMove(dt)
	
	if love.keyboard.isDown(control.up) then
		player.y = player.y - player.speed * dt
		player.direction = 2
		player.iterator = player.iterator + 1
	end
	
	if love.keyboard.isDown(control.down) then
		player.y = player.y + player.speed * dt
		player.direction = 1
		player.iterator = player.iterator + 1
	end

	if love.keyboard.isDown(control.right) then
		player.x = player.x + player.speed * dt
		player.direction = 3
		player.iterator = player.iterator + 1
	end

	if love.keyboard.isDown(control.left) then
		player.x = player.x - player.speed * dt
		player.direction = 4
		player.iterator = player.iterator + 1
	end

end

function playerTimer(dt)

	if player.iterator > 4 then
		player.iterator = 1
	end

end

wat ya mean she's in another castle!?
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Animating

Post by Kasperelo »

uh... It worked. Didn't need to make an empty table. Weird. But now, if you walk around a little he's gonna dance like an idiot.
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Animating

Post by Kasperelo »

Fixed! Yeah!
Attachments
yeah.love
(15.81 KiB) Downloaded 167 times
Showle1943
Prole
Posts: 1
Joined: Fri May 25, 2012 1:47 am
Contact:

Re: Animating

Post by Showle1943 »

Kasperelo wrote:Hm. Kinda works, but for some reason one of the frames doesn't show up?
I'm having the same issue. Anybody figure this out yet? I'm a newbie so be gentle. :3
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Animating

Post by Kasperelo »

Showle1943 wrote:
Kasperelo wrote:Hm. Kinda works, but for some reason one of the frames doesn't show up?
I'm having the same issue. Anybody figure this out yet? I'm a newbie so be gentle. :3
Fixed it! Here's the script. PM me what you don't understand, if there's something unclear.
Attachments
animation.love
(2.1 KiB) Downloaded 128 times
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot] and 11 guests