First, I have two pictures. One, let's say, idle1.png, and the other, idle2.png. idle1.png would be facing right, for when player was walking right, and the other idle picture would be facing left, for when player was walking left. Now, is it possible for Love2d to detect which side the player was walking last? If so, I would really like to know.
If some of you still don't understand, here's what I mean.
Player is walking right, then stops. The idle would be idle1.png, which is facing right.
Player is walking left, then stops. The idle would be idle2.png, which is facing left.
Help, please?
Here is my code
NOTE: Yes, I have AnAL (Animations And LOVE)
Code: Select all
require 'AnAL'
----
function love.load()
love.graphics.setBackgroundColor(255,255,255)
imgIdle = love.graphics.newImage('/sprites/animationidle.png')
imgLeft = love.graphics.newImage('/sprites/animationleft.png')
imgRight = love.graphics.newImage('/sprites/animationright.png')
animIdle = newAnimation(imgIdle, 60, 64, 0.2, 0)
animLeft = newAnimation(imgLeft, 66, 64, 0.2, 0)
animRight = newAnimation(imgRight, 66, 64, 0.2, 0)
x=100
y=100
speed=200
end
----
function love.update(dt)
if (love.keyboard.isDown('left')) then
face='left'
x=x-speed*dt
animLeft:update(dt)
elseif (love.keyboard.isDown('right')) then
face='right'
x=x+speed*dt
animRight:update(dt)
else
face='idle'
animIdle:update(dt)
end
end
----
function love.draw()
if (face=='left') then
animLeft:draw(x,y)
end
if (face=='right') then
animRight:draw(x,y)
end
if (face=='idle') then
animIdle:draw(x,y)
end
end