Walk animation!?
Moderators: Shine, Insert_witty_name
Walk animation!?
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!
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!
-
- Posts: 64
- Joined: Fri Jul 15, 2005 11:44 pm
-
- Posts: 64
- Joined: Fri Jul 15, 2005 11:44 pm
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[man]<10 and pad:start()==false do
pad=Controls.read()
--object,x,y,limit of frames,alpha value
walk(man,100,100,300,6,true)
screen.waitVblankStart()
screen.flip()
screen:clear()
end
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!
Last edited by imhotep on Tue Apr 25, 2006 9:53 pm, edited 6 times in total.
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
xpos and ypos i mean
Code: Select all
animation={}
animtimer={}
path_no={}
pathtimer={}
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
if walkstep==nil then walkstep=1 end
screen:blit(x,y,objectname[walkstep],alphavalue)
--end if
end
--end else
end
return animdone
--end function
end
function path(objectX,objectY,timelimit,limit)
if limit==nil then
path_no[objectX]=1
pathtimer[objectX]=Timer.new(0)
pathtimer[objectX]:start()
objectX={}
objectY={}
else
if pathtimer[objectX]:time()>timelimit then
pathtimer[objectX]:stop()
pathtimer[objectX]:reset()
pathtimer[objectX]:start()
path_no[objectX]=path_no[objectX]+1
end
if path_no[objectX]>limit then
path_no[objectX]=1
pathgone=true
pathtimer[objectX]:stop()
pathtimer[objectX]:reset()
pathtimer[objectX]:start()
end
nowX=objectX[path_no[objectX]]
nowY=objectY[path_no[objectX]]
end
return pathgone,nowX,nowY
end
--main
--call init, this example a man walking
walk(man)
--init movement
manX={}
manY={}
manX[1],manY[1]=50,50
manX[2],manY[2]=60,50
manX[3],manY[3]=70,50
manX[4],manY[4]=80,50
manX[5],manY[5]=70,50
manX[6],manY[6]=60,50
manX[7],manY[7]=50,50
path(manX)
--animate 10 times
pad=Controls.read()
while animation[man]<10 and pad:start()==false do
pad=Controls.read()
--object,x,y,limit of frames,alpha value
path(manX,manY,300,7)
walk(man,nowX,nowY,300,6,true)
screen.waitVblankStart()
screen.flip()
screen:clear()
end