The first problem I see is the
love.timer.sleep in the player.update function. You don't need that and it kills your frame rate because the main loop (the love.run function) call love.update and then the love.draw function.
The second problem is that you add your speed (32), so the sprite teleport around. If you want a progressive walk, use speed*dt to modify your player.x
Another problem is that the first thing you do when a key is down is to restart the walk cycle. (sorry for my syntax)
I don't know what you want so I suppose you don't want a grid locked char, so here is an example of player.lua with progressive moving :
I use your player.pnum as picture num and player.pic to indicate the pictures' table you want to display.
wpic in function player.update is the wanted picture table.
I use player.speed as the horizontal speed of the player (negative to left, positive to right).
I increase player.speed but ANIME_TIMER and player.speed need some tuning for a good feeling.
The main change are in the player.update function.
Code: Select all
player = {}
player.x = 100
player.y = 100
player.speed = 64
local ANIM_TIMER=0.25
playerL = {}
playerL[1] = love.graphics.newImage("image/left_00.png")
playerL[2] = love.graphics.newImage("image/left_01.png")
playerL[3] = love.graphics.newImage("image/left_02.png")
playerL[4] = love.graphics.newImage("image/left_03.png")
playerL[5] = love.graphics.newImage("image/left_04.png")
playerL[6] = love.graphics.newImage("image/left_05.png")
playerL[7] = love.graphics.newImage("image/left_06.png")
playerR = {}
playerR[1] = love.graphics.newImage("image/right_00.png")
playerR[2] = love.graphics.newImage("image/right_01.png")
playerR[3] = love.graphics.newImage("image/right_02.png")
playerR[4] = love.graphics.newImage("image/right_03.png")
playerR[5] = love.graphics.newImage("image/right_04.png")
playerR[6] = love.graphics.newImage("image/right_05.png")
playerR[7] = love.graphics.newImage("image/right_06.png")
player.animTimer = 0
player.pic = playerR
player.pnum = 1
function player.update(dt)
if love.keyboard.isDown("right","left") then
local wpic = love.keyboard.isDown("left") and playerL or playerR
if player.pic ~= wpic then
player.pic = wpic
player.pnum=1
player.animTimer=ANIM_TIMER
player.speed = -player.speed
end
player.animTimer = player.animTimer - dt
if player.animTimer < 0 then
player.animTimer=ANIM_TIMER
player.pnum = player.pnum +1
if player.pnum > #player.pic then
player.pnum=1
end
end
player.x = player.x + player.speed*dt
else
player.pnum=1
end
end
function player.draw()
love.graphics.draw(player.pic[player.pnum], player.x, player.y)
end