Page 1 of 1

The way of the animation!

Posted: Mon Oct 06, 2003 9:18 am
by LarsG
I'm about to mess around with animation, and I was wondering what was everybody's favourite way of animation?!
I am thinking of images, sprites or whatever you fancy.
How you store the animation strip (images in one file, or several files), and how you use it, in terms of animation speed, timing etc.

Maybe I (and others too!!) can pickup a some pointers and/or code snippets to play around with...

-Lars

Posted: Tue Oct 07, 2003 12:34 am
by J. Baker
I believe you're talking about 2D images for games but a nice piece of software for animating 3D files is Character FX. Only 15 US dollars too.
http://www.insanesoftware.de/

Posted: Tue Oct 07, 2003 9:48 am
by LarsG
Yes, I was talking about 2D animation. Allthough this Character FX program seems nice.
I've heard of it before, but I allways thought this was a professional (read expensive) piece of software. :) Maybe Iæll buy it... :wink:

But I wasn't speaking of software in my last post. I was leaning more towards how people used animation in their programs. How they set it up (constant wise), and how they did their timing, etc...

But thanks anyway J.B. :)

-Lars

Posted: Tue Oct 07, 2003 1:36 pm
by Kale
Here is a very small example of one way to do it: http://www.garyw.uklinux.net/PB/Sprite%20Viewer.zip I've use a timing method called forced timing to know when events or animation take place on screen, this makes sure the animation plays at the same speed regardless of cpu. There are other ways of doing this. Also i prefer any animated sprites to be kept in one file then clipped up in the code :)

Posted: Wed Oct 08, 2003 10:45 am
by LarsG
Thanks Kale.. :)

-Lars

Posted: Wed Oct 08, 2003 1:05 pm
by Num3
Check out PURETOOLS I from Danilo, he has a module to handle animations which is very good, here are the available commands:

AnimSprite Overview
AnimSprite
CreateAnimSprite() Create an AnimSprite out of a PureBasic sprite
DisplayAnimSprite() Display an animated sprite

Animation Control - Automation

SetAnimLoopDelay() Set the delay time between frames
SetAnimLoopDirection() Set the direction for automatic frame animation


Animation Control - Frames


SetAnimFrame() Set a new current frame in the AnimSprite
NextAnimFrame() Set the animation to the next frame
PrevAnimFrame() Set the animation to the previous frame


Animation Control - Directions

SetAnimDirection() Set a new current direction in the AnimSprite
NextAnimDirection() Set the animation to the next direction
PrevAnimDirection() Set the animation to the previous direction

Animation Collision Checking

CollisionAnimAnim() Check collision between 2 AnimSprites
CollisionAnimSprite() Check collision AnimSprite vs. Sprite
CollisionSpriteAnim() Check collision Sprite vs. AnimSprite

Get Animation Info

CurrentAnimFrame() Get the currently used frame number
CurrentAnimDirection() Get the currently used direction number
AnimFrameCount() Get the count of frames in an AnimSprite
AnimDirectionCount() Get the count of directions in an AnimSprite
AnimLoopDelay() Get the current delay between frames
AnimLoopDirection() Get the current direction for automatic animation


Here's a code example:

Code: Select all

InitSprite()
InitKeyboard()
InitMouse()

If OpenScreen(800,600,32,"TEST") = 0    ; test 32bit
 If OpenScreen(800,600,24,"TEST") = 0   ; if 32bit failed, test 24bit
  If OpenScreen(800,600,16,"TEST") = 0  ; if 32/24 failed, try 16bit screen
     MessageRequester("ERROR","Cant open 16/24/32bit Screen",0):End
  EndIf
 EndIf
EndIf

   ; limit Speed
   SetFrameRate(20)

   ; Load Anim-Sprites
   CatchSprite(1,?Soldier,0)
   TransparentSpriteColor(1,255,255,255)
   CreateAnimSprite(Soldier.AnimSprite,1,57,59)
   SoldierX = 500 : SoldierY = 400

   CatchSprite(2,?Fighter,0)
   TransparentSpriteColor(2,255,255,255)
   CreateAnimSprite(Fighter.AnimSprite,2,119,89)
   FighterX = 400 : FighterY = 380



Repeat
     FlipBuffers()
     If IsScreenActive()
       ClearScreen($66,$66,$66)
       R = 0 : G = 0 : B = 0

       DisplayAnimSprite(Soldier,SoldierX,SoldierY)
       DisplayAnimSprite(Fighter,FighterX,FighterY)
       
       If CollisionAnimAnim(Fighter,FighterX,FighterY,Soldier,SoldierX,SoldierY): Dead = 1: EndIf
       If Dead = 1
          NextAnimFrame(Soldier): frame + 1
          If frame = 10: Quit = 1: EndIf
       EndIf
       If DoAnim = 1: NextAnimFrame(Fighter): EndIf


       ; KEYBOARD CHECK
       ;
       ExamineKeyboard()
       If KeyboardPushed(#PB_Key_Right): DoAnim = 1: EndIf
       sleep_(1)
   Else
       sleep_(200)
   EndIf
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Beep_(1400,50): Delay(1500)
End

Soldier:
IncludeBinary "Soldier.bmp"
Fighter:
IncludeBinary "Fighter.bmp"
 
[/size]

Posted: Wed Oct 08, 2003 2:14 pm
by LarsG
Yes Num3, thanks for the reply..
I allready got PureTools from Danilo earlier today.. :p

-Lars