 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
What
Joined: 16 Apr 2006 Posts: 4
|
Posted: Mon Apr 24, 2006 9:08 am Post subject: 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! |
|
| Back to top |
|
 |
DiabloTerrorGF
Joined: 15 Jul 2005 Posts: 64
|
Posted: Mon Apr 24, 2006 12:06 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
DiabloTerrorGF
Joined: 15 Jul 2005 Posts: 64
|
Posted: Mon Apr 24, 2006 12:07 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
What
Joined: 16 Apr 2006 Posts: 4
|
Posted: Tue Apr 25, 2006 12:49 am Post subject: |
|
|
| thanks for the help. |
|
| Back to top |
|
 |
Giuliano
Joined: 13 Sep 2005 Posts: 78
|
Posted: Tue Apr 25, 2006 10:03 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
DiabloTerrorGF
Joined: 15 Jul 2005 Posts: 64
|
Posted: Tue Apr 25, 2006 10:05 am Post subject: |
|
|
| I hate LUA arrays/tables |
|
| Back to top |
|
 |
Giuliano
Joined: 13 Sep 2005 Posts: 78
|
Posted: Tue Apr 25, 2006 10:15 am Post subject: |
|
|
| DiabloTerrorGF wrote: | | I hate LUA arrays/tables |
It's almost the same as a normal array and arrays are a must in programs :) |
|
| Back to top |
|
 |
imhotep
Joined: 13 Dec 2005 Posts: 41
|
Posted: Tue Apr 25, 2006 8:52 pm Post subject: |
|
|
| Code: | 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 |
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!

Last edited by imhotep on Tue Apr 25, 2006 9:53 pm; edited 6 times in total |
|
| Back to top |
|
 |
imhotep
Joined: 13 Dec 2005 Posts: 41
|
Posted: Tue Apr 25, 2006 9:42 pm Post subject: |
|
|
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: | 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 |
|
|
| Back to top |
|
 |
What
Joined: 16 Apr 2006 Posts: 4
|
Posted: Mon May 01, 2006 12:55 pm Post subject: |
|
|
| Thanks for the code |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|