Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
void CAnimation::Show(CSprite* pSprite, int pCoordX, int pCoordY) { int time = timeGetTime(); if(time - LastChange >= PictureDuration && Running) { if(++Position == Textures.end()) Position = Textures.begin(); LastChange = time; } pSprite->ShowTexture((*Position), pCoordX, pCoordY); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
class CAnimation { public: void Create(int pPictureDuration); void AddPicture(CTexture* pTexture); void Show(CSprite* pSprite, int pCoordX, int pCoordY); void Start(); void Stop(); void Reset(); private: std::list<CTexture*> Textures; std::list<CTexture*>::iterator Position; int PictureDuration; int LastChange; bool Running; }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include "global.h" void CAnimation::Create(int pPictureDuration) { PictureDuration = pPictureDuration; Position = Textures.begin(); } void CAnimation::AddPicture(CTexture* pTexture) { Textures.push_back(pTexture); } void CAnimation::Show(CSprite* pSprite, int pCoordX, int pCoordY) { int time = timeGetTime(); if(time - LastChange >= PictureDuration && Running) { if(++Position == Textures.end()) Position = Textures.begin(); LastChange = time; } pSprite->ShowTexture((*Position), pCoordX, pCoordY); } void CAnimation::Start() { Running = true; } void CAnimation::Stop() { Running = false; } void CAnimation::Reset() { Position = Textures.begin(); } |
Zitat von »"newby"«
danke für deine hilfe, daran hat es gelegen, war natürlich ein doofer denkfehler das mit den konstruktoren ist auch ne gute Idee, warum ne Create funktion schreiben wenn man einen konstruktor hat
Werbeanzeige