Animator créez vos animation de sprites 2D

Programmation d'applications complexes
Avatar de l’utilisateur
microdevweb
Messages : 1798
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Animator créez vos animation de sprites 2D

Message par microdevweb »

Bonjour à tous,

Je travaille de plus en plus avec les modules car ce qui est fait n'est plus à faire, j'ai créer un module pour l'animation de sprite 2D :arrow: http://www.purebasic.fr/french/viewtopi ... =6&t=14803

J'ai maintenant développer un logiciel (je l'ai fait en Anglais car je penses le poster sur le forum Anglais) pour gérer vos animations très facilement (de concert avec le module)

Image

Tout est ICi :arrow: http://www.alldev.be/ALLDEV_WEB/TUTO/An ... imator.zip

Vous pouvez jouer avec les séquences et changer le frame rate pour chaque séquence, ce logiciel peut également vous servir lorsque vous dessinez vos sprites, pour voir le résultat directement.(dessinez votre animation comme sur l’exemple du zip).

Après vous cliquez Copy to clipboard et collez le code dans vos procédure d'animation.

Dans vos jeux
N'oubliez pas d'inclure le module

Code : Tout sélectionner

XIncludeFile "Animator.pbi"
pour démarrer l'animation

Code : Tout sélectionner

Animator::Start(IdAnimation)
Dans la boucle de vos jeux

Code : Tout sélectionner

Animator::Animation(IdAnimation)
Regardez dans le DeclareModule Animator, pour les autres possibilités

Voila en espérant que cela vous sera utile
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Avatar de l’utilisateur
microdevweb
Messages : 1798
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Nouvelle version

Message par microdevweb »

Code : Tout sélectionner

;//////////////////////////////////////////////////////////////////////////////////////////////////////////
; © MicrodevWeb 2014
;Nom: Module Animator
;Vers: 1.1
;Date Départ: 23/09/2014
;Date fin: 23/09/2014
;Nouvelle Vers :25/09/2014
;Auteur: Bielen Pierre
;Description: Module pour l'animation des sprites
;Vers 1.1 --> FrameRate individuelle pour chaque séquence
;//////////////////////////////////////////////////////////////////////////////////////////////////////////
DeclareModule Animator
      Declare Create(IdAnimation,IdSprite,SpriteSize,FrameRate,loopMode.b=#True)
      Declare AddImage(IdAnimation,LineStart,ColumnStart,NumberImage,FrameRate=-1)
      Declare SetAnimFrameRate(IdAnimation,FrameRate)
      Declare.i GetAnimFrameRate(IdAnimation)
      Declare.i GetCurrentFrame(IdAnimation)
      Declare Start(IdAnimation)
      Declare Animation(IdAnimation)
      Declare SetModeLoop(IdAnimation,loopMode)
      Declare.b GetModeLoop(IdAnimation)
      Declare StopAnimation(IdAnimation,State.b=#True)
      Declare.b GetAnimationState(IdAnimation)
      Declare FreeAnimation(IdAnimation)
      Declare SetOneRateFrame(IdAnimation,FrameIndex,FrameRate)
EndDeclareModule
Module Animator
      EnableExplicit
      UsePNGImageDecoder()
      ;-*Structures
      Structure ImgAnimation
            X.i ;La position X sur la feuille d'animation
            Y.i ;La position Y sur la feuille d'animation
            FrameRate.i
      EndStructure
      Structure Animation
            IdSprite.i
            SpriteSize.i
            List myImgAnimation.ImgAnimation()
            TimeStart.i
            FrameRate.i
            *CurrentFrame
            loopMode.b
            Stoped.b
      EndStructure 
      ;}--------------------------------------------------------------------------------------------------------------------------------
      ;-*Variables
      Global NewMap myAnimation.Animation()
      ;}--------------------------------------------------------------------------------------------------------------------------------
      ;-*Procédures
      Procedure  Create(IdAnimation,IdSprite,SpriteSize,FrameRate,loopMode.b=#True)
            AddMapElement(myAnimation(),Str(IdAnimation))
            With myAnimation()
                  \IdSprite=IdSprite
                  \SpriteSize=SpriteSize
                  \FrameRate=FrameRate
                  \CurrentFrame=-1
                  \TimeStart=0
                  \loopMode=loopMode
                  \Stoped=#False
            EndWith
      EndProcedure
      Procedure OpenAnimation(IdAnimation)
            If FindMapElement(myAnimation(),Str(IdAnimation))=0
                  MessageRequester("Error","This animation "+Str(IdAnimation)+" Not exist...")
                  ProcedureReturn #False
            EndIf
            ProcedureReturn #True
      EndProcedure
      Procedure AddImage(IdAnimation,LineStart,ColumnStart,NumberImage,FrameRate=-1)
            Protected  N=0,Y=0,X=0
            If Not OpenAnimation(IdAnimation):ProcedureReturn #False :EndIf
            With myAnimation()
                  Y=\SpriteSize*LineStart
                  X=\SpriteSize*ColumnStart
                  For N=0 To NumberImage-1
                        If X>=SpriteWidth(\IdSprite)
                              X=0
                              Y+\SpriteSize
                        EndIf
                        AddElement(\myImgAnimation())
                        \myImgAnimation()\X=X
                        \myImgAnimation()\Y=Y
                        If FrameRate<>-1
                              \myImgAnimation()\FrameRate=FrameRate
                        Else
                              \myImgAnimation()\FrameRate=myAnimation()\FrameRate
                        EndIf
                        X+\SpriteSize
                  Next
            EndWith
      EndProcedure
      Procedure SetAnimFrameRate(IdAnimation,FrameRate)
            If Not OpenAnimation(IdAnimation):ProcedureReturn #False :EndIf
            With myAnimation()  
                  \FrameRate=FrameRate
                  ForEach \myImgAnimation()
                        \myImgAnimation()\FrameRate=FrameRate
                  Next
            EndWith
      EndProcedure
      Procedure SetOneRateFrame(IdAnimation,FrameIndex,FrameRate)
            If Not OpenAnimation(IdAnimation):ProcedureReturn #False :EndIf
            SelectElement(myAnimation()\myImgAnimation(),FrameIndex)
            With myAnimation()\myImgAnimation() 
                  \FrameRate=FrameRate
            EndWith
      EndProcedure
      Procedure.i GetAnimFrameRate(IdAnimation)
            If Not OpenAnimation(IdAnimation):ProcedureReturn -1 :EndIf
            With myAnimation()  
                  ProcedureReturn \FrameRate
            EndWith
      EndProcedure
      Procedure.i GetCurrentFrame(IdAnimation)
            If Not OpenAnimation(IdAnimation):ProcedureReturn -1 :EndIf
            With myAnimation()  
                  ProcedureReturn ListIndex(\myImgAnimation())
            EndWith
      EndProcedure
      Procedure Start(IdAnimation)
            If Not OpenAnimation(IdAnimation):ProcedureReturn #False :EndIf
            With myAnimation()  
                  myAnimation()\TimeStart=ElapsedMilliseconds()
                  FirstElement(myAnimation()\myImgAnimation())
                  myAnimation()\CurrentFrame=@myAnimation()\myImgAnimation()
                  ClipSprite(\IdSprite,myAnimation()\myImgAnimation()\X,myAnimation()\myImgAnimation()\Y,\SpriteSize,\SpriteSize)
            EndWith
            ProcedureReturn #True
      EndProcedure
      Procedure Animation(IdAnimation)
            If Not OpenAnimation(IdAnimation):ProcedureReturn #False :EndIf
            With myAnimation()  
                  If \Stoped=#True :ProcedureReturn #True :EndIf
                  If ElapsedMilliseconds()-\TimeStart>\myImgAnimation()\FrameRate
                        ;Si pas sur la dernière image de l'animation
                        If ListIndex(\myImgAnimation())<(ListSize(\myImgAnimation())-1)
                              NextElement(\myImgAnimation())
                        Else
                              If \loopMode=#True
                                    FirstElement(\myImgAnimation())
                              EndIf
                        EndIf
                        ClipSprite(\IdSprite,myAnimation()\myImgAnimation()\X,myAnimation()\myImgAnimation()\Y,\SpriteSize,\SpriteSize)
                        \CurrentFrame=@\myImgAnimation()
                        \TimeStart=ElapsedMilliseconds()
                  EndIf
            EndWith
            ProcedureReturn #True
      EndProcedure
      Procedure SetModeLoop(IdAnimation,loopMode)
            If Not OpenAnimation(IdAnimation):ProcedureReturn #False :EndIf
            With myAnimation()  
                  \loopMode=loopMode
            EndWith
            ProcedureReturn #True
      EndProcedure
      Procedure.b GetModeLoop(IdAnimation)
            If Not OpenAnimation(IdAnimation):ProcedureReturn #False :EndIf
            With myAnimation()  
                  ProcedureReturn \loopMode
            EndWith
      EndProcedure
      Procedure StopAnimation(IdAnimation,State.b=#True)
            If Not OpenAnimation(IdAnimation):ProcedureReturn #False :EndIf
            With myAnimation()  
                  \Stoped=State
            EndWith
      EndProcedure
      Procedure.b GetAnimationState(IdAnimation)
            If Not OpenAnimation(IdAnimation):ProcedureReturn #False :EndIf
            With myAnimation()  
                  ProcedureReturn  \Stoped
            EndWith
      EndProcedure
      Procedure FreeAnimation(IdAnimation)
            If Not OpenAnimation(IdAnimation):ProcedureReturn #False :EndIf
            DeleteMapElement(myAnimation())
            ProcedureReturn #True
      EndProcedure
      ;}--------------------------------------------------------------------------------------------------------------------------------
EndModule

Et un logiciel pour tout gèrer...

:arrow: http://www.purebasic.fr/french/viewtopi ... =3&t=14808
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Avatar de l’utilisateur
TazNormand
Messages : 1294
Inscription : ven. 27/oct./2006 12:19
Localisation : Calvados (14)

Re: Animator créez vos animation de sprites 2D

Message par TazNormand »

Salut MicroDevWeb,

J'ai fusionné tes 2 messages. Evites de faire 50 topics, si tu fais des MàJ de tes softs, édites le topic initial.

voili voilou
Image
Image
Répondre