diff options
-rw-r--r-- | engines/draci/animation.cpp | 24 | ||||
-rw-r--r-- | engines/draci/animation.h | 5 | ||||
-rw-r--r-- | engines/draci/game.cpp | 14 |
3 files changed, 31 insertions, 12 deletions
diff --git a/engines/draci/animation.cpp b/engines/draci/animation.cpp index adcb8e2d82..74e876401d 100644 --- a/engines/draci/animation.cpp +++ b/engines/draci/animation.cpp @@ -33,6 +33,8 @@ Animation::Animation(DraciEngine *vm) : _vm(vm) { _z = 0; _relX = 0; _relY = 0; + _scaleX = 1.0; + _scaleY = 1.0; _playing = false; _looping = false; _tick = _vm->_system->getMillis(); @@ -69,6 +71,10 @@ void Animation::markDirtyRect(Surface *surface) { // Translate rectangle to compensate for relative coordinates frameRect.translate(_relX, _relY); + + // Take animation scaling into account + frameRect.setWidth(frameRect.width() * _scaleX); + frameRect.setHeight(frameRect.height() * _scaleY); // Mark the rectangle dirty on the surface surface->markDirtyRect(frameRect); @@ -141,12 +147,23 @@ void Animation::drawFrame(Surface *surface) { frame->setX(newX); frame->setY(newY); + // Save scaled width and height + int scaledWidth = frame->getScaledWidth(); + int scaledHeight = frame->getScaledHeight(); + + // Take into account per-animation scaling and adjust the current frames dimensions + if (_scaleX != 1.0 || _scaleY != 1.0) + frame->setScaled(scaledWidth * _scaleX, scaledHeight * _scaleY); + // Draw frame frame->drawScaled(surface, false); // Revert back to old coordinates frame->setX(x); frame->setY(y); + + // Revert back to old dimensions + frame->setScaled(scaledWidth, scaledHeight); } } @@ -183,6 +200,13 @@ void Animation::setPlaying(bool playing) { _playing = playing; } +void Animation::setScaleFactors(double scaleX, double scaleY) { + markDirtyRect(_vm->_screen->getSurface()); + + _scaleX = scaleX; + _scaleY = scaleY; +} + void Animation::addFrame(Drawable *frame) { _frames.push_back(frame); } diff --git a/engines/draci/animation.h b/engines/draci/animation.h index 0e29934699..683af7c812 100644 --- a/engines/draci/animation.h +++ b/engines/draci/animation.h @@ -66,6 +66,8 @@ public: int getRelativeX(); int getRelativeY(); + void setScaleFactors(double scaleX, double scaleY); + void markDirtyRect(Surface *surface); private: @@ -79,6 +81,9 @@ private: int _relX; int _relY; + double _scaleX; + double _scaleY; + uint _tick; bool _playing; bool _looping; diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index 2a0e5dca6f..de925fe11f 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -193,21 +193,11 @@ void Game::loop() { // We naturally want the dragon to position its feet to the location of the // click but sprites are drawn from their top-left corner so we subtract // the current height of the dragon's sprite - // We also need to do this before we change the frames' scaled dimensions - // so setRelative() can correctly delete the old frame y -= (int)(scaleY * height); anim->setRelative(x, y); - // Set the scaled dimensions for all frames - for (uint i = 0; i < anim->getFramesNum(); ++i) { - frame = anim->getFrame(i); - - // Calculate scaled dimensions - uint scaledWidth = (uint)(scaleX * frame->getWidth()); - uint scaledHeight = (uint)(scaleY * frame->getHeight()); - - frame->setScaled(scaledWidth, scaledHeight); - } + // Set the per-animation scaling factor + anim->setScaleFactors(scaleX, scaleY); // Play the animation _vm->_anims->play(animID); |