From 23e39ef3eccab6b1297a00d3f8f199b54a7e9af9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 15 Apr 2013 01:32:12 +0300 Subject: improve ambientlayer class. --- src/resources/ambientlayer.cpp | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'src/resources/ambientlayer.cpp') diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp index b32a93bf0..ba10cbdcc 100644 --- a/src/resources/ambientlayer.cpp +++ b/src/resources/ambientlayer.cpp @@ -40,29 +40,28 @@ AmbientLayer::AmbientLayer(Image *const img, const float parallax, if (!mImage) return; - if (keepRatio && !imageHelper->useOpenGL() - /*&& defaultScreenWidth != 0 - && defaultScreenHeight != 0*/ - && mainGraphics->mWidth != defaultScreenWidth - && mainGraphics->mHeight != defaultScreenHeight) + if (keepRatio && !imageHelper->useOpenGL()) { - // Rescale the overlay to keep the ratio as if we were on - // the default resolution... - Image *const rescaledOverlay = ResourceManager::getInstance()-> - getRescaled(mImage, static_cast(mImage->mBounds.w) - / defaultScreenWidth * mainGraphics->mWidth, - static_cast(mImage->mBounds.h) - / defaultScreenHeight * mainGraphics->mHeight); - - if (rescaledOverlay) - mImage = rescaledOverlay; - else - mImage->incRef(); - } - else - { - mImage->incRef(); + const int width = mainGraphics->mWidth; + const int height = mainGraphics->mHeight; + if (width != defaultScreenWidth && height != defaultScreenHeight) + { + // Rescale the overlay to keep the ratio as if we were on + // the default resolution... + Image *const rescaledOverlay = ResourceManager::getInstance()-> + getRescaled(mImage, static_cast(mImage->mBounds.w) + / defaultScreenWidth * width, + static_cast(mImage->mBounds.h) + / defaultScreenHeight * height); + + if (rescaledOverlay) + mImage = rescaledOverlay; + else + mImage->incRef(); + return; + } } + mImage->incRef(); } AmbientLayer::~AmbientLayer() @@ -79,27 +78,28 @@ void AmbientLayer::update(const int timePassed, const float dx, const float dy) if (!mImage) return; + const float time = static_cast(timePassed) / 10; // Self scrolling of the overlay - mPosX -= mSpeedX * static_cast(timePassed) / 10; - mPosY -= mSpeedY * static_cast(timePassed) / 10; + mPosX -= mSpeedX * time; + mPosY -= mSpeedY * time; // Parallax scrolling mPosX += dx * mParallax; mPosY += dy * mParallax; - const int imgW = mImage->mBounds.w; - const int imgH = mImage->mBounds.h; + const float imgW = mImage->mBounds.w; + const float imgH = mImage->mBounds.h; // Wrap values while (mPosX > imgW) - mPosX -= static_cast(imgW); + mPosX -= imgW; while (mPosX < 0) - mPosX += static_cast(imgW); + mPosX += imgW; while (mPosY > imgH) - mPosY -= static_cast(imgH); + mPosY -= imgH; while (mPosY < 0) - mPosY += static_cast(imgH); + mPosY += imgH; } void AmbientLayer::draw(Graphics *const graphics, const int x, -- cgit v1.2.3-60-g2f50