Add option to define beginFrame
Used function overloading for backwards compatibility Also add a getter to check if the sprite is animating (because protected)
This commit is contained in:
parent
c2039cf254
commit
66892f846a
|
@ -58,7 +58,7 @@ protected:
|
||||||
bool stayWithinBounds;
|
bool stayWithinBounds;
|
||||||
u32 imageSize, tileIndex;
|
u32 imageSize, tileIndex;
|
||||||
SpriteSize spriteSize;
|
SpriteSize spriteSize;
|
||||||
u32 animationDelay, amountOfFrames, currentFrame, animationCounter;
|
u32 animationDelay, amountOfFrames, beginFrame, currentFrame, animationCounter;
|
||||||
bool animating;
|
bool animating;
|
||||||
|
|
||||||
std::unique_ptr<OBJ_ATTR> oam;
|
std::unique_ptr<OBJ_ATTR> oam;
|
||||||
|
@ -78,6 +78,13 @@ public:
|
||||||
this->animationDelay = animationDelay;
|
this->animationDelay = animationDelay;
|
||||||
animate();
|
animate();
|
||||||
}
|
}
|
||||||
|
void makeAnimated(int beginFrame, int amountOfFrames, int animationDelay) {
|
||||||
|
this->amountOfFrames = amountOfFrames;
|
||||||
|
this->animationDelay = animationDelay;
|
||||||
|
this->beginFrame = beginFrame;
|
||||||
|
this->currentFrame = beginFrame;
|
||||||
|
animate();
|
||||||
|
}
|
||||||
void animate() { this->animating = true; }
|
void animate() { this->animating = true; }
|
||||||
void animateToFrame(int frame) { this->currentFrame = frame; }
|
void animateToFrame(int frame) { this->currentFrame = frame; }
|
||||||
void stopAnimating() { this->animating = false; }
|
void stopAnimating() { this->animating = false; }
|
||||||
|
@ -107,6 +114,7 @@ public:
|
||||||
u32 getWidth() { return w; }
|
u32 getWidth() { return w; }
|
||||||
u32 getY() { return y; }
|
u32 getY() { return y; }
|
||||||
u32 getCurrentFrame() { return currentFrame; }
|
u32 getCurrentFrame() { return currentFrame; }
|
||||||
|
bool isAnimating() { return animating; };
|
||||||
bool isOffScreen();
|
bool isOffScreen();
|
||||||
|
|
||||||
friend class SpriteManager;
|
friend class SpriteManager;
|
||||||
|
|
|
@ -14,7 +14,7 @@ Sprite::Sprite(const Sprite &other) : Sprite(nullptr, 0, other.x, other.y, other
|
||||||
|
|
||||||
Sprite::Sprite(const void *imageData, int imageSize, int x, int y, SpriteSize size)
|
Sprite::Sprite(const void *imageData, int imageSize, int x, int y, SpriteSize size)
|
||||||
: x(x), y(y), data(imageData), imageSize(imageSize), spriteSize(size),
|
: x(x), y(y), data(imageData), imageSize(imageSize), spriteSize(size),
|
||||||
animationDelay(0), amountOfFrames(0), currentFrame(0), animationCounter(0) {
|
animationDelay(0), amountOfFrames(0), beginFrame(0), currentFrame(0), animationCounter(0) {
|
||||||
setAttributesBasedOnSize(size);
|
setAttributesBasedOnSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +86,11 @@ void Sprite::updateAnimation() {
|
||||||
animationCounter++;
|
animationCounter++;
|
||||||
if(animationCounter > animationDelay) {
|
if(animationCounter > animationDelay) {
|
||||||
currentFrame++;
|
currentFrame++;
|
||||||
if(currentFrame > (amountOfFrames - 1)) {
|
if(currentFrame > (amountOfFrames - 1) + beginFrame) {
|
||||||
currentFrame = 0;
|
currentFrame = beginFrame;
|
||||||
|
}
|
||||||
|
if(currentFrame < beginFrame) {
|
||||||
|
currentFrame = beginFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
animationCounter = 0;
|
animationCounter = 0;
|
||||||
|
|
Loading…
Reference in New Issue