Home Hardware Networking Programmazione Software Domanda Sistemi
Conoscenza Informatica >> software >> Software di animazione >> .

Tutorial su SDL a scorrimento laterale

Simple DirectMedia Layer permette di accedere ad audio , tastiera, mouse , joystick , OpenGL 3D hardware e 2 - D Video framebuffer . Usato con il software di riproduzione MPEG , emulatori e altri giochi , il programma SDL è utile per una varietà di cose , come ad esempio l'animazione di un gioco di scorrimento laterale. SDL funziona nativamente con il C + + , ma funziona anche in C , Ada , C # , D , Eiffell , Erlang , Euphoria , Go , Guile , Haskell , Java , Lisp , Lua , ML , Objective C , Pascal , Perl , PHP , Pike , Pliant , Python, Ruby , Smalltalk e Tcl . Istruzioni
1

creare due nuovi file chiamati " CAnimation.h " e aggiungere la seguente direttiva "include" in " CApp.h " " CAnimation.cpp /. " : " # include ' CAnimation.h ' "
2

Open" CAnimation.h "e inserire il seguente codice: .

# ifndef _CANIMATION_H_ # define _CANIMATION_H_ # include < SDL . h > class CAnimation {private : int currentFrame ; int FrameInc ; private : int FrameRate ; //millisecondi lungo oldtime ; pubblici: int MaxFrames ; pubblici: CAnimation ( ) ; vuoto OnAnimate ( ) ; pubblici: SetFrameRate void ( int Rate) ; vuoto SetCurrentFrame ( int frame) ; int GetCurrentFrame (); }; # endif
3

Aperto " CAnimation.cpp " e inserire il seguente codice con i tuoi valori di frame rate : # include " CAnimation.h " CAnimation :: CAnimation ( ) { currentFrame = 0; MaxFrames = 0; FrameInc = 1; FrameRate = 100; //millisecondi oldtime = 0; }

vuoto CAnimation :: OnAnimate ( ) {if ( oldtime + FrameRate > SDL_GetTicks ( ) ) { return; } oldtime = SDL_GetTicks (); currentFrame + = FrameInc ; se ( FrameInc > 0 ) {if ( currentFrame > = MaxFrames - 1) { FrameInc = - FrameInc ; } } else {if ( currentFrame < = 0 ) { FrameInc = - FrameInc ; } } } else {if ( currentFrame > = MaxFrames - 1) { currentFrame = 0; } } } vuoto CAnimation :: SetFrameRate (int Vota ) { framerate = cambio ; } vuoto CAnimation :: SetCurrentFrame ( int frame) {if (telaio < 0

 

software © www.354353.com