From 9581f6556ac1646b4d30c676403aba544e4edaec Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Thu, 24 Aug 2006 00:58:21 +0000 Subject: scrolling and overlays are no longer linked to the framerate --- src/map.cpp | 87 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 34 deletions(-) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index 6eec4865..463a8c8e 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -171,54 +171,73 @@ Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY) { std::list::iterator i; + static int lastTick = tick_time; + + // Avoid freaking out when tick_time overflows + if (tick_time < lastTick) + { + lastTick = tick_time; + } + if (mLastScrollX == 0.0f && mLastScrollY == 0.0f) { + // first call - initialisation mLastScrollX = scrollX; mLastScrollY = scrollY; } - for (i = mOverlays.begin(); i != mOverlays.end(); i++) + //update Overlays + while (lastTick < tick_time) { - - if ((*i).image != NULL) + for (i = mOverlays.begin(); i != mOverlays.end(); i++) { - //apply self scrolling - (*i).scrollX -= (*i).scrollSpeedX; - (*i).scrollY -= (*i).scrollSpeedY; + if ((*i).image != NULL) + { + //apply self scrolling + (*i).scrollX -= (*i).scrollSpeedX; + (*i).scrollY -= (*i).scrollSpeedY; - //apply parallaxing - (*i).scrollX += (scrollX - mLastScrollX) * (*i).parallax; - (*i).scrollY += (scrollY - mLastScrollY) * (*i).parallax; + //apply parallaxing + (*i).scrollX += (scrollX - mLastScrollX) * (*i).parallax; + (*i).scrollY += (scrollY - mLastScrollY) * (*i).parallax; - //keep the image pattern on the screen - while ((*i).scrollX > (*i).image->getWidth()) - { - (*i).scrollX -= (*i).image->getWidth(); - } - while ((*i).scrollY > (*i).image->getHeight()) - { - (*i).scrollY -= (*i).image->getHeight(); - } - while ((*i).scrollX < 0) - { - (*i).scrollX += (*i).image->getWidth(); - } - while ((*i).scrollY < 0) - { - (*i).scrollY += (*i).image->getHeight(); + //keep the image pattern on the screen + while ((*i).scrollX > (*i).image->getWidth()) + { + (*i).scrollX -= (*i).image->getWidth(); + } + while ((*i).scrollY > (*i).image->getHeight()) + { + (*i).scrollY -= (*i).image->getHeight(); + } + while ((*i).scrollX < 0) + { + (*i).scrollX += (*i).image->getWidth(); + } + while ((*i).scrollY < 0) + { + (*i).scrollY += (*i).image->getHeight(); + } } - - graphics->drawImagePattern ( (*i).image, - 0 - (int)(*i).scrollX, - 0 - (int)(*i).scrollY, - graphics->getWidth() + (int)(*i).scrollX, - graphics->getHeight() + (int)(*i).scrollY - ); } + mLastScrollX = scrollX; + mLastScrollY = scrollY; + lastTick++; } - mLastScrollX = scrollX; - mLastScrollY = scrollY; + //draw overlays + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + if ((*i).image != NULL) + { + graphics->drawImagePattern ( (*i).image, + 0 - (int)(*i).scrollX, + 0 - (int)(*i).scrollY, + graphics->getWidth() + (int)(*i).scrollX, + graphics->getHeight() + (int)(*i).scrollY + ); + }; + }; } void -- cgit v1.2.3-70-g09d2