News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Another way for Sprite Animation

Started by Duncki, August 09, 2005, 04:39:05 PM

Previous topic - Next topic

Duncki

I have made a little example for a sprite Animation.
They are a few bugs but you can seen what i want.
For example the Number of repeats, the number after
the  "A" you can change it ,but nothing will happend.

If anybody has better Idea feel free to change it.

PlayBASIC Code: [Select]
; PROJECT : SetSpriteAnimation
; AUTHOR : Andreas
; CREATED : 09.08.2005
; EDITED : 09.08.2005
; ---------------------------------------------------------------------
;make a simple aniamtion
Cls RGB(0,0,0)
For b=1 To 6
Circle 15,15,b*3,0
GetImage b,0,0,32,32
Cls RGB(0,0,0)

Next b


CreateSprite 1
SpriteImage 1,6
;define the Animation
;A stand for Animation , 0 said enless animation
;the other parameter is (Frame,Delay)....
SetSpriteAnimation(1,"A0(1,140)(2,40)(3,140)(5,40)(6,180)(1,9)")
While Not EscKey()
Cls RGB(0,0,0)
PositionSprite 1,50,50
AnimateSprite(1);Animate it
DrawSprite 1
Sync

EndWhile
End


Function AnimateSprite(sprn)
Static r,ani,time,fl
l=GetSpriteLocalWord(sprn,0)+2;length of Animation
w=GetSpriteLocalWord(sprn,2);number of Repeat
;timer...
If Timer()>time+fl
fl=GetSpriteLocalWord(sprn,ani+2)
ani=ani+4:r=r+1;animframe an current length of anim
If r=l
ani=4:r=0
EndIf
time=Timer()
EndIf
SpriteImage sprn,GetSpriteLocalWord(sprn,ani);put it to the sprite
EndFunction


Psub SetSpriteAnimation(sprn,anim$)
Dim MyAnim$(1)
;i use the split to array command
tokens=SplitToArray(anim$,"A (,)",MyAnim$(),1)
CreateSpriteLocals 1,tokens*4
mem=2
For lp=2 To tokens
If myAnim$(lp)<>""
l=l+1
;and put it as sprite local data
SpriteLocalWord sprn,mem,Int(Val(myanim$(lp)))
mem=mem+2
EndIf
SpriteLocalWord sprn,0,l
Next
EndPsub







greetings
Duncki :)

Draco9898

#1
Well see, I don't know why'd you'd have a set amount of times you'd want to loop since this could easily be controlled by a State flag, I.E: AnimState=1 for Idle animation, ETC

Also what I do is just use a timing routine to increase frames by milliseconds until the frames have ran out and I just go back to the first frame in a set animation. This timing routine not only allows me to make animations using only two varibles (Just CurrentFrame, and FrameTime), I also use it for handling menu times and such
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

kevin

#2
Duncki,

 That's clever a approach, I really enjoyed your use of Split to Array and local data..  It's one of my favorite commands :)

 My only concern is with the static locals like the 'time' value in the function.  It might be better storing the last timer() time the sprite was last updated in the sprites local data also.   So calls to the function are updating the sprite from it's last update, rather than from when the function was last called.   As it might cause hiccups when animating a number of sprites.  Although that's just a guess !

 The other change that's prolly worth making would be to place the frame stepping code into a repeat/until.  So if it's been a long time between updates, the animation can step forward and over the frames that have been missed during this time period..

 So the logic look at bit like this perhaps

 CurrentTimer=timer()
 LastUpdateTime=GetSpriteLocalInt(sprn,Timeaddress)

 If CurrentTimer>LastUpdateTime
    Repeat
       Change the frame counter
       LastUpdateTime=LastUpdateTime+FrameLengthTime
    until LastUpdateTime=>CurrentTime
endif

SpriteLocalInt sprn,Timeaddress,LastUpdateTime

Duncki

#3
Hi ,
thank you for your help.
I have question , the idea I found on the Bmax(blitzmax) :rolleyes:  board.
This guy made it like Amal ,Kevin you now that is what i want.
And now the Question, is the same in PlayBasic possible?

Here the link to BlitzBasic .

(login required)

Greeting
:D

Duncki

kevin

#4
Hmm, I don't see any reason why your system above couldn't evolve into something like that. Seems to be already heading down that track anyway.

   Just need to expand upon your existing parser and the tokenized controls.  So you'd create animation script, which might house the frame lists,  anim cycles, and movement paths. in one.     Although I guess it'd be better if you could define the frame lists and animations on their own... Then assign them a movement path which could change animations at will.    Save a bit of double up defining the same animations for differ paths.

   This could set up externally in  uff or xml format..  

   So, Just rambling off the top of head here.. this could looking something like this..




 ; Define Frames/Object classes
 <Frames>
    Objects=Player,BadBuy  

    <player>
         files= "Playerframe1.bmp","Playerframe2.bmp","Playerframe3.bmp"
    </player>

    <badguy>
          files="Badguy1.bmp",  "Badguy2.bmp","Badguy3.bmp"
    </badguy>

</Frames>

 
; define animations
 <Animations>
      <player>
        ; Format  -  Frame Index from objects animation list and a time/frame counter)  
          Left= "(0-10), (1-20),(0-20)"
       <player>        
 </Animations>

<Paths>
   etc
</Paths>

<Maps>
   etc
</Maps>  



   My gut feeling is that It's prolly best for having animation layers ( As their might be various types of animation systems. )supplied in plib format.   Which is how most, if not all future command sets will be developed anyway.  Even a lot existing tidbits will soon find themselves presented in this fashion. So we can trim the fat.   While at this point, this does mean that the library is effectively a source library. But In PB1.10 (perhaps PB1.09)  they'll be binary modules.  

   This would allow us or users to build fully encapsulated systems, on top the base commands.  They should execute just fast as any internal commands.  But I digress.


  Related Articles:
    * Frame Sheet Animation Library