diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/map.cpp | 8 | ||||
-rw-r--r-- | src/resources/ambientoverlay.cpp | 32 | ||||
-rw-r--r-- | src/resources/ambientoverlay.h | 16 |
4 files changed, 34 insertions, 26 deletions
@@ -8,6 +8,10 @@ actually added one). * src/properties.h: Added convenience method to read a property as a float. + * src/map.cpp, src/resources/ambientoverlay.cpp, + src/resources/ambientoverlay.h: Resolved some weirdness involving + the terms scroll and speed. + 2006-10-07 Eugenio Favalli <elvenprogrammer@gmail.com> diff --git a/src/map.cpp b/src/map.cpp index 8e85e6ee..05dea951 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -98,16 +98,14 @@ Map::initializeOverlays() const std::string name = "overlay" + toString(i); Image *img = resman->getImage(getProperty(name + "image")); - float scrollX = getFloatProperty(name + "scrollX"); - //float scrollY = getFloatProperty(name + "scrollY"); + float speedX = getFloatProperty(name + "scrollX"); + float speedY = getFloatProperty(name + "scrollY"); float parallax = getFloatProperty(name + "parallax"); if (img) { - // TODO: For some reason scrollX is passed as speedX and speedY. - // Maybe Crush knows why? mOverlays.push_back( - new AmbientOverlay(img, parallax, 0, 0, scrollX, scrollX)); + new AmbientOverlay(img, parallax, speedX, speedY)); // The AmbientOverlay takes control over the image. img->decRef(); diff --git a/src/resources/ambientoverlay.cpp b/src/resources/ambientoverlay.cpp index b5304627..058b6083 100644 --- a/src/resources/ambientoverlay.cpp +++ b/src/resources/ambientoverlay.cpp @@ -28,9 +28,9 @@ #include "../graphics.h" AmbientOverlay::AmbientOverlay(Image *img, float parallax, - float scrollX, float scrollY, float speedX, float speedY): + float speedX, float speedY): mImage(img), mParallax(parallax), - mScrollX(scrollX), mScrollY(scrollY), + mPosX(0), mPosY(0), mSpeedX(speedX), mSpeedY(speedY) { mImage->incRef(); @@ -44,30 +44,30 @@ AmbientOverlay::~AmbientOverlay() void AmbientOverlay::update(int timePassed, float dx, float dy) { // Self scrolling of the overlay - mScrollX -= mSpeedX * timePassed / 10; - mScrollY -= mSpeedY * timePassed / 10; + mPosX -= mSpeedX * timePassed / 10; + mPosY -= mSpeedY * timePassed / 10; // Parallax scrolling - mScrollX += dx * mParallax; - mScrollY += dy * mParallax; + mPosX += dx * mParallax; + mPosY += dy * mParallax; int imgW = mImage->getWidth(); int imgH = mImage->getHeight(); // Wrap values - while (mScrollX > imgW) - mScrollX -= imgW; - while (mScrollX < 0) - mScrollX += imgW; + while (mPosX > imgW) + mPosX -= imgW; + while (mPosX < 0) + mPosX += imgW; - while (mScrollY > imgH) - mScrollY -= imgH; - while (mScrollY < 0) - mScrollY += imgH; + while (mPosY > imgH) + mPosY -= imgH; + while (mPosY < 0) + mPosY += imgH; } void AmbientOverlay::draw(Graphics *graphics, int x, int y) { - graphics->drawImagePattern(mImage, (int)(-mScrollX), (int)(-mScrollY), - x + (int)mScrollX, y + (int)mScrollY); + graphics->drawImagePattern(mImage, + (int) -mPosX, (int) -mPosY, x + (int) mPosX, y + (int) mPosY); } diff --git a/src/resources/ambientoverlay.h b/src/resources/ambientoverlay.h index 25bc28ef..a939cbb4 100644 --- a/src/resources/ambientoverlay.h +++ b/src/resources/ambientoverlay.h @@ -30,9 +30,15 @@ class Image; class AmbientOverlay { public: + /** + * Constructor. + */ AmbientOverlay(Image *img, float parallax, - float scrollX, float scrollY, float speedX, float speedY); + float speedX, float speedY); + /** + * Destructor. + */ ~AmbientOverlay(); void update(int timePassed, float dx, float dy); @@ -42,10 +48,10 @@ class AmbientOverlay private: Image *mImage; float mParallax; - float mScrollX; - float mScrollY; - float mSpeedX; - float mSpeedY; + float mPosX; /**< Current layer X position. */ + float mPosY; /**< Current layer Y position. */ + float mSpeedX; /**< Scroll speed in X direction. */ + float mSpeedY; /**< Scroll speed in Y direction. */ }; #endif |