Vitajte na [www.pocitac.win] Pripojiť k domovskej stránke Obľúbené stránky
Vytvorte dva nové súbory s názvom " CAnimation.h " a pridať nasledujúce " patrí " smernicu " CApp.h " " CAnimation.cpp /. " " # include " CAnimation.h ' "
2
Otvoriť " CAnimation.h " a zadajte nasledujúci kód : .
# ifndef _CANIMATION_H_ # define _CANIMATION_H_ # include < SDL . h > class CAnimation { private : int currentFrame , int FrameInc , private : int Frekvencia snímkov ; //milisekundy dlhé oldtime , public : int MaxFrames ; public : CAnimation ( ) ; void OnAnimate ( ) ; public : void SetFrameRate ( int Rate ) ; void SetCurrentFrame ( int Frame ) ; int GetCurrentFrame ( ) ; } ; # endif
3
Otvoriť " CAnimation.cpp " a zadajte nasledujúci kód s hodnotami pre počet snímok za sekundu : # include " CAnimation.h " CAnimation :: CAnimation ( ) { currentFrame = 0 ; MaxFrames = 0 ; FrameInc = 1 ; Frekvencia snímkov = 100 ; //milisekundy oldtime = 0 ;
} void CAnimation :: OnAnimate ( ) { if ( oldtime + Frekvencia snímok > SDL_GetTicks ( ) ) { return ; } oldtime = SDL_GetTicks ( ) ; currentFrame + = FrameInc ; if ( FrameInc > 0 ) { if ( currentFrame > = MaxFrames - 1 ) { FrameInc = - FrameInc ; } } else { if ( currentFrame < = 0 ) { FrameInc = - FrameInc ; } } } else { if ( currentFrame > = MaxFrames - 1 ) { currentFrame = 0 ; } } } void CAnimation :: SetFrameRate ( int Hodnotiť ) { Frekvencia snímkov = rýchlosť ; } void CAnimation :: SetCurrentFrame ( int Frame ) { if ( rám < 0
Copyright © počítačové znalosti Všetky práva vyhradené