Walk animation!?

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
What
Posts: 4
Joined: Sun Apr 16, 2006 6:06 am

Walk animation!?

Post by What »

I need some help...
Im trying to make an walk animation with 3 pictures but I don't know how, I have tryed and look at others scripts but I just get confused. Please help me!
DiabloTerrorGF
Posts: 64
Joined: Fri Jul 15, 2005 11:44 pm

Post by DiabloTerrorGF »

walking=false
step=0
----

if walking==true
step+=1
if step==1
screen:blit(x,x,first walk)
end
if step==2
screen:blit(x,x,second walk)
end
if step==3
scree:blit(x,x, third walk)
end
if step==3
step = 0
end
end
DiabloTerrorGF
Posts: 64
Joined: Fri Jul 15, 2005 11:44 pm

Post by DiabloTerrorGF »

whoops,

you can can combine those if step==3

Also, that might appear fast, so can do thing like multiply all the numbers to 10 or something to make them appear mopre regular.
What
Posts: 4
Joined: Sun Apr 16, 2006 6:06 am

Post by What »

thanks for the help.
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

That's a really dirty way of doing it though . I would recommend an array (table) that contains the animation and then simply loading the values from that
DiabloTerrorGF
Posts: 64
Joined: Fri Jul 15, 2005 11:44 pm

Post by DiabloTerrorGF »

I hate LUA arrays/tables
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

DiabloTerrorGF wrote:I hate LUA arrays/tables
It's almost the same as a normal array and arrays are a must in programs :)
imhotep
Posts: 41
Joined: Tue Dec 13, 2005 9:15 pm

Post by imhotep »

Code: Select all

animation={}
animtimer={}

man={}
for i=1,6 do
        man[i]=Image.load("man"..i..".png")
end

function walk(objectname,x,y,timelimit,limit,alphavalue)
animdone=false

--init?
if limit==nil then
        animtimer[objectname]=Timer.new()
        animtimer[objectname]:start()
        walkstep=1
        animation[objectname]=1
else

if animtimer[objectname]:time()>=timelimit then
        walkstep=walkstep+1
        animtimer[objectname]:stop()
	animtimer[objectname]:reset()
        animtimer[objectname]:start()
end

if walkstep>limit then
        walkstep=1
        animdone=true
        animtimer[objectname]:stop()
	animtimer[objectname]:reset()
        animtimer[objectname]:start()
        animation[objectname]=animation[objectname]+1
else
        screen:blit(x,y,objectname[walkstep],alphavalue)
--end if
end

--end else
end

return animdone
--end function
end


--main

--call init, this example a man walking

walk(man)

--animate 10 times

pad=Controls.read()
while animation&#91;man&#93;<10 and pad&#58;start&#40;&#41;==false do
pad=Controls.read&#40;&#41;

--object,x,y,limit of frames,alpha value
walk&#40;man,100,100,300,6,true&#41;
	screen.waitVblankStart&#40;&#41;
	screen.flip&#40;&#41;
	screen&#58;clear&#40;&#41;
end
WORKING CODE

the good thing about this code is: you just have to call the function once
with an object name to initialize everything, it can be used for all objects
in your game.
you just need an array that has the same name as your object
(in this case man[number] ). that means all timers are configured
through this simple script, ergo all animations are done with this.

variables: function walk(objectname,x,y,timelimit,limit,alphavalue)
objectname: give the object the same name as the array with the frames.
x,y: coordinates where to blit
timelimit: time in milliseconds to change the frame
limit: but change it only until it reaches frame X
alphavalue: alpha value of the frame


BELOW ARE THE PIX USED... ENJOY!

Image
Image
Image
Image
Image
Image
Last edited by imhotep on Tue Apr 25, 2006 9:53 pm, edited 6 times in total.
imhotep
Posts: 41
Joined: Tue Dec 13, 2005 9:15 pm

Post by imhotep »

btw you can incorporate a position change, too if you make a table with presets where the man should stay in which frame.
xpos and ypos i mean

Code: Select all

animation=&#123;&#125;
animtimer=&#123;&#125;
path_no=&#123;&#125;
pathtimer=&#123;&#125;

man=&#123;&#125;
for i=1,6 do
        man&#91;i&#93;=Image.load&#40;"man"..i..".png"&#41;
end

function walk&#40;objectname,x,y,timelimit,limit,alphavalue&#41;
animdone=false

--init?
if limit==nil then
        animtimer&#91;objectname&#93;=Timer.new&#40;&#41;
        animtimer&#91;objectname&#93;&#58;start&#40;&#41;
        walkstep=1
        animation&#91;objectname&#93;=1
else

if animtimer&#91;objectname&#93;&#58;time&#40;&#41;>=timelimit then
        walkstep=walkstep+1
        animtimer&#91;objectname&#93;&#58;stop&#40;&#41;
   animtimer&#91;objectname&#93;&#58;reset&#40;&#41;
        animtimer&#91;objectname&#93;&#58;start&#40;&#41;
end

if walkstep>limit then
        walkstep=1
        animdone=true
        animtimer&#91;objectname&#93;&#58;stop&#40;&#41;
   animtimer&#91;objectname&#93;&#58;reset&#40;&#41;
        animtimer&#91;objectname&#93;&#58;start&#40;&#41;
        animation&#91;objectname&#93;=animation&#91;objectname&#93;+1
else

	if walkstep==nil then walkstep=1 end
	screen&#58;blit&#40;x,y,objectname&#91;walkstep&#93;,alphavalue&#41;
--end if
end

--end else
end

return animdone
--end function
end

function path&#40;objectX,objectY,timelimit,limit&#41;

if limit==nil then
	path_no&#91;objectX&#93;=1
	pathtimer&#91;objectX&#93;=Timer.new&#40;0&#41;
	pathtimer&#91;objectX&#93;&#58;start&#40;&#41;
	objectX=&#123;&#125;
	objectY=&#123;&#125;
else

if pathtimer&#91;objectX&#93;&#58;time&#40;&#41;>timelimit then
	pathtimer&#91;objectX&#93;&#58;stop&#40;&#41;
	pathtimer&#91;objectX&#93;&#58;reset&#40;&#41;
	pathtimer&#91;objectX&#93;&#58;start&#40;&#41;
	path_no&#91;objectX&#93;=path_no&#91;objectX&#93;+1
end

if path_no&#91;objectX&#93;>limit then
	path_no&#91;objectX&#93;=1
	pathgone=true
	pathtimer&#91;objectX&#93;&#58;stop&#40;&#41;
	pathtimer&#91;objectX&#93;&#58;reset&#40;&#41;
	pathtimer&#91;objectX&#93;&#58;start&#40;&#41;
end

nowX=objectX&#91;path_no&#91;objectX&#93;&#93;
nowY=objectY&#91;path_no&#91;objectX&#93;&#93;

end

return pathgone,nowX,nowY

end

--main

--call init, this example a man walking

walk&#40;man&#41;

--init movement
manX=&#123;&#125;
manY=&#123;&#125;

manX&#91;1&#93;,manY&#91;1&#93;=50,50
manX&#91;2&#93;,manY&#91;2&#93;=60,50
manX&#91;3&#93;,manY&#91;3&#93;=70,50
manX&#91;4&#93;,manY&#91;4&#93;=80,50
manX&#91;5&#93;,manY&#91;5&#93;=70,50
manX&#91;6&#93;,manY&#91;6&#93;=60,50
manX&#91;7&#93;,manY&#91;7&#93;=50,50

path&#40;manX&#41;

--animate 10 times

pad=Controls.read&#40;&#41;
while animation&#91;man&#93;<10 and pad&#58;start&#40;&#41;==false do
pad=Controls.read&#40;&#41;

--object,x,y,limit of frames,alpha value
path&#40;manX,manY,300,7&#41;
walk&#40;man,nowX,nowY,300,6,true&#41;
   screen.waitVblankStart&#40;&#41;
   screen.flip&#40;&#41;
   screen&#58;clear&#40;&#41;
end
What
Posts: 4
Joined: Sun Apr 16, 2006 6:06 am

Post by What »

Thanks for the code
Post Reply