Animating
Posted: Sun May 20, 2012 11:01 am
Please help me! I'm not sure what's wrong with the animation.
Code: Select all
player.iterator = player.iterator + dt
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
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?
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?