Animating
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Animating
I think it may be the line(s) in 'player.lua':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.
Code: Select all
player.iterator = player.iterator + dt
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.
Re: Animating
OK!
I'll try
I'll try
Re: Animating
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.
Re: Animating
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
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!?
Re: Animating
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.
-
- Prole
- Posts: 1
- Joined: Fri May 25, 2012 1:47 am
- Contact:
Re: Animating
I'm having the same issue. Anybody figure this out yet? I'm a newbie so be gentle.Kasperelo wrote:Hm. Kinda works, but for some reason one of the frames doesn't show up?
Re: Animating
Fixed it! Here's the script. PM me what you don't understand, if there's something unclear.Showle1943 wrote:I'm having the same issue. Anybody figure this out yet? I'm a newbie so be gentle.Kasperelo wrote:Hm. Kinda works, but for some reason one of the frames doesn't show up?
- Attachments
-
- animation.love
- (2.1 KiB) Downloaded 128 times
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot] and 11 guests