Fix handling for spritesheets with multiple rows

This commit is contained in:
GriffinR 2025-05-26 20:12:21 -04:00
parent 27c7df1288
commit 3efd7683ab
2 changed files with 8 additions and 12 deletions

View File

@ -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

View File

@ -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));
}