Re: Create a waking animation through pictures and keypresse
Posted: Mon Feb 20, 2012 2:06 pm
Well, if you don't mind It's messy and it's inconsistent but what I'm looking to do it assign all directions to be like the hero = walking_up assignment and then eventually have the single image pose when the button is released. but at the moment, the hero = walking_up assignment isn't working as expected...
Code: Select all
function love.load()
require("AnAL")
background = love.graphics.newImage("bg.png")
local imgup = love.graphics.newImage("/hero/heroanimeup.png")
walking_up = newAnimation(imgup, 71, 100.5, 0.1, 3)
local imgdown = love.graphics.newImage("/hero/heroanimedown.png")
walking_down = newAnimation(imgdown, 71, 100.5, 0.1, 3)
local imgright = love.graphics.newImage("/hero/heroanimeright.png")
walking_right = newAnimation(imgright, 71, 100.5, 0.1, 3)
local imgleft = love.graphics.newImage("/hero/heroanimeleft.png")
walking_left = newAnimation(imgleft, 71, 100.5, 0.1, 3)
heroRightS = love.graphics.newImage("/hero/5.png")
heroLeftS = love.graphics.newImage("/hero/11.png")
heroDownS = love.graphics.newImage("/hero/fstand.png")
heroUpS = love.graphics.newImage("/hero/1.png")
hero = heroDownS -- the player starts looking to the left
x = 300
y = 400
speed = 100
end
function love.update(dt)
walking_up:update(dt)
-- keyboard actions for our hero
if love.keyboard.isDown("a") then
x = x - (speed*dt)
hero = heroLeftS
elseif love.keyboard.isDown("d") then
x = x + (speed*dt)
hero = heroRightS
end
if love.keyboard.isDown("w") then
y = y - (speed*dt)
hero = walking_up
elseif love.keyboard.isDown("s") then
y = y + (speed*dt)
hero = heroDownS
end
end
function love.draw()
love.graphics.draw(background)
love.graphics.draw(hero, x, y)
hero:draw(100, 100)
end