hello as I can make a walking animation pokemon style with love2d
I have the following file using an animation, but not it's what I want.
please help.
helps animation to walk in a rpg game. - (Solved)
- luislasonbra
- Citizen
- Posts: 60
- Joined: Sun Jun 24, 2012 1:57 pm
helps animation to walk in a rpg game. - (Solved)
Last edited by luislasonbra on Mon Sep 02, 2013 10:52 am, edited 1 time in total.
Re: helps animation to walk in a rpg game.
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.
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
- luislasonbra
- Citizen
- Posts: 60
- Joined: Sun Jun 24, 2012 1:57 pm
Re: helps animation to walk in a rpg game.
chezrom wrote: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
hello the animation I want to achieve is this
but I can not get the code for the animation.
- luislasonbra
- Citizen
- Posts: 60
- Joined: Sun Jun 24, 2012 1:57 pm
Re: helps animation to walk in a rpg game.
luislasonbra wrote:chezrom wrote: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
hello the animation I want to achieve is this
but I can not get the code for the animation.
hi thanks I've managed to make the animations.
here I leave the code in case anyone is interested.
Who is online
Users browsing this forum: No registered users and 3 guests