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...
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
The problem is that you're mixing an matching without the matching. You have both animations and still images, but your drawing code doesn't differentiate, it just tries to do both.
I would recommend making everything an animation. Yes, even the still images- a 1 frame animation isn't going to destroy your performance, but it WILL make your code way simpler.
Thanks for the tip! I've taken it on board. At the moment though, I'm still running into an issue where when I press I direction it throws a "attempt to call method 'draw' (a nil value)" error regarding this line
function love.load()
require("AnAL")
local imgup = love.graphics.newImage("/hero/heroanimeup.png")
walking_up = newAnimation(imgup, 71, 101, 0.1, 3)
local imgdown = love.graphics.newImage("/hero/heroanimedown.png")
walking_down = newAnimation(imgdown, 71, 101, 0.1, 3)
local imgright = love.graphics.newImage("/hero/heroanimeright.png")
walking_right = newAnimation(imgright, 71, 101, 0.1, 3)
local imgleft = love.graphics.newImage("/hero/heroanimeleft.png")
walking_left = newAnimation(imgleft, 71, 101, 0.1, 3)
hero = walking_down
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 = walking_left
elseif love.keyboard.isDown("d") then
x = x + (speed*dt)
hero = walking_right
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 = walking_down
end
end
function love.draw()
hero:draw(x, y)
end
In case anyone wonders how it has been solved (it is generally viewed as good manners to post a solution to your problem if you find it yourself), only the up animation got updated in love.update.