From 3efd7683abf037ae539fdc23b279316bfcefb9b7 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 26 May 2025 20:12:21 -0400 Subject: [PATCH] Fix handling for spritesheets with multiple rows --- CHANGELOG.md | 1 + src/project.cpp | 19 +++++++------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 516891b6..021c6430 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -129,6 +129,7 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp - Fix `Open Map Scripts` not working on maps with a `shared_scripts_map` field. - Fix the main window sometimes exceeding the screen size on first launch. - Fix right-click selections with the eyedropper clearing when the mouse is released. +- Fix overworld sprite facing directions if spritesheet is arranged in multiple rows. ## [5.4.1] - 2024-03-21 ### Fixed diff --git a/src/project.cpp b/src/project.cpp index 5c1d73bf..75612248 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -3109,7 +3109,7 @@ QPixmap Project::getEventPixmap(const QString &gfxName, int frame, bool hFlip) { // Set this whether we were successful or not, we only need to try to load it once. gfx->loaded = true; } - if (!gfx || gfx->spritesheet.isNull()) { + if (!gfx || gfx->spritesheet.width() == 0 || gfx->spritesheet.height() == 0) { // Either we didn't recognize the gfxName, or we were unable to load the sprite's image. return QPixmap(); } @@ -3118,18 +3118,13 @@ QPixmap Project::getEventPixmap(const QString &gfxName, int frame, bool hFlip) { if (gfx->inanimate) { img = gfx->spritesheet.copy(0, 0, gfx->spriteWidth, gfx->spriteHeight); } else { - int x = 0; - int y = 0; + int x = frame * gfx->spriteWidth; + int y = ((frame * gfx->spriteWidth) / gfx->spritesheet.width()) * gfx->spriteHeight; - // Get frame's position in spritesheet. - // Assume horizontal layout. If position would exceed sheet width, try vertical layout. - if ((frame + 1) * gfx->spriteWidth <= gfx->spritesheet.width()) { - x = frame * gfx->spriteWidth; - } else if ((frame + 1) * gfx->spriteHeight <= gfx->spritesheet.height()) { - y = frame * gfx->spriteHeight; - } - - img = gfx->spritesheet.copy(x, y, gfx->spriteWidth, gfx->spriteHeight); + img = gfx->spritesheet.copy(x % gfx->spritesheet.width(), + y % gfx->spritesheet.height(), + gfx->spriteWidth, + gfx->spriteHeight); if (hFlip) { img = img.transformed(QTransform().scale(-1, 1)); }