It is currently Sat Jul 11, 2020 7:15 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: how can i animate a simple sprite ?
PostPosted: Sun Jan 28, 2018 2:46 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Dec 04, 2015 9:26 pm
Posts: 287
hi everyone !

how can i animate a simple sprite , and show him ?


Top
 Profile  
Reply with quote  
 Post subject: Re: how can i animate a simple sprite ?
PostPosted: Sun Jan 28, 2018 6:28 am 
Offline
Addict
Addict
User avatar

Joined: Sun Apr 27, 2003 8:12 am
Posts: 2042
Location: USA
I think this is my last revision of AnimateSprite() procedure. This is for sprite strips. If you need/use sprite sheet code, then click this link...
viewtopic.php?p=284416#p284416

Code:
Structure AnimatedSprites
  asNextFrame.b
  asClipOnce.b
  asNextStill.b
  asFps.b
  asData.b
EndStructure

Procedure AnimateSprite(asSprite, asClipSquare, asStartFrame, asEndFrame, asFpsDelay) ;<--- For a still frame, use 0 for "asFpsDelay".

  Static Dim asSprites.AnimatedSprites(100) ;<--- Set to the maximum #Sprite number you plan to use with this procedure.
 
    If asSprites(asSprite)\asData <> 1 ;<--- Only need this data to start off with.
        asSprites(asSprite)\asNextFrame = 0
        asSprites(asSprite)\asClipOnce = 0
        asSprites(asSprite)\asNextStill = asStartFrame
        asSprites(asSprite)\asFps = 1
        asSprites(asSprite)\asData = 1
    EndIf
   
    If asStartFrame + asSprites(asSprite)\asNextFrame > asEndFrame ;<--- Already clipped the last frame and need to start from the begining.
        asSprites(asSprite)\asNextFrame = 0
    EndIf
   
    If asSprites(asSprite)\asNextStill <> asStartFrame Or asSprites(asSprite)\asNextStill <> asEndFrame;<--- If you go from one still frame to the next still frame or animation, we reset "asClipOnce".
        asSprites(asSprite)\asClipOnce = 0
        asSprites(asSprite)\asNextStill = asStartFrame ;<--- If we go to an animation, we don't want this "If" statement to keep calculating "asClipOnce = 0".
    EndIf
   
    If asStartFrame = asEndFrame And asSprites(asSprite)\asClipOnce = 0 ;<--- No need to keep clipping a still frame.
        ClipSprite(asSprite, ((asStartFrame + asSprites(asSprite)\asNextFrame) * asClipSquare) - asClipSquare, 0, asClipSquare, asClipSquare)
        asSprites(asSprite)\asClipOnce = 1
        asSprites(asSprite)\asNextStill = asStartFrame
    ElseIf asStartFrame < asEndFrame ;<--- Clipping for animation.
        ClipSprite(asSprite, ((asStartFrame + asSprites(asSprite)\asNextFrame) * asClipSquare) - asClipSquare, 0, asClipSquare, asClipSquare)
    EndIf
       
    If asSprites(asSprite)\asFps = asFpsDelay ;<--- Checking for "frames per second" before going to the next frame.
        asSprites(asSprite)\asNextFrame + 1
        asSprites(asSprite)\asFps = 1
    ElseIf asFpsDelay <> 0 ;<--- Not equal to a still frame or full blast 60fps animation or higher.
        asSprites(asSprite)\asFps + 1
    EndIf
   
  ProcedureReturn asStartFrame + asSprites(asSprite)\asNextFrame ;<--- If you want an event to react different depending on the current frame number.
           
EndProcedure

_________________
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 12 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye