From a60cdb3ab7e55bfe20ec2ba0bed354fbe10813c5 Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 25 Apr 2020 14:57:05 -0700 Subject: [PATCH] Fix the 2nd to 4th tiles of moving plats rendering offset from 1st tile This commit fixes a bug where the second, third, and fourth tiles of moving platforms would render offset from the first tile if the moving platform hit the top or left edge of the screen. This is due to the fact that SDL_BlitSurface() will end up changing the coordinates of the rectangle we pass to it to be 0 if they're negative, but only after it's already been drawn. Previously, we kept re-using the same rectangle each time we drew each segment of the moving platform, but since it only changes the draw rectangle after it's already been drawn, the first tile shows up fine, but not the rest of the tiles, hence resulting in an offset. To fix this, we do the same thing as we did for drawing the "really big sprite" (size-type 9): just reset the rectangle we use every time we draw a segment of the moving platform. --- desktop_version/src/Graphics.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 696063f7..e27587e8 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -1532,9 +1532,6 @@ void Graphics::drawentities() // Special: Moving platform, 4 tiles or 8 tiles tpoint.x = obj.entities[i].xp; tpoint.y = obj.entities[i].yp; - drawRect = tiles_rect; - drawRect.x += tpoint.x; - drawRect.y += tpoint.y; int thiswidth = 4; if (obj.entities[i].size == 8) { @@ -1542,8 +1539,11 @@ void Graphics::drawentities() } for (int ii = 0; ii < thiswidth; ii++) { + drawRect = tiles_rect; + drawRect.x += tpoint.x; + drawRect.y += tpoint.y; + drawRect.x += 8 * ii; BlitSurfaceStandard((*tilesvec)[obj.entities[i].drawframe],NULL, backBuffer, &drawRect); - drawRect.x += 8; } } else if (obj.entities[i].size == 3) // Big chunky pixels!