summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-03-05 13:20:18 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2025-03-07 22:27:48 +0100
commitad8a68be501d8ffef9fbfceacdc4c13b84a0d74a (patch)
tree97469f00f818ab3130e841f2b94a6a9259e13b76 /src
parenta1bc8e1974d04a111127b744413094a886de4de6 (diff)
downloadmana-ad8a68be501d8ffef9fbfceacdc4c13b84a0d74a.tar.gz
mana-ad8a68be501d8ffef9fbfceacdc4c13b84a0d74a.tar.bz2
mana-ad8a68be501d8ffef9fbfceacdc4c13b84a0d74a.tar.xz
mana-ad8a68be501d8ffef9fbfceacdc4c13b84a0d74a.zip
Introduced spriteOffsetY setting to replace half tile hack
For historical reasons, sprites get a 16 pixel offset by default, which is used to position them correctly on their tile. When pixel-based movement was added, actors are now positioned on the middle of a tile and the built-in offset was removed. Servers that use sprites that do not rely on this offset can now set the spriteOffsetY option to 0.
Diffstat (limited to 'src')
-rw-r--r--src/actorsprite.cpp20
-rw-r--r--src/being.cpp7
-rw-r--r--src/defaults.cpp5
-rw-r--r--src/gui/widgets/playerbox.cpp5
4 files changed, 12 insertions, 25 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp
index 28d5bed3..7cb46bd4 100644
--- a/src/actorsprite.cpp
+++ b/src/actorsprite.cpp
@@ -58,13 +58,7 @@ ActorSprite::~ActorSprite()
int ActorSprite::getDrawOrder() const
{
- int drawOrder = Actor::getDrawOrder();
-
- // See note at ActorSprite::draw
- if (mMap)
- drawOrder += mMap->getTileHeight() / 2;
-
- return drawOrder;
+ return Actor::getDrawOrder() + paths.getIntValue("spriteOffsetY");
}
bool ActorSprite::draw(Graphics *graphics, int offsetX, int offsetY) const
@@ -75,17 +69,12 @@ bool ActorSprite::draw(Graphics *graphics, int offsetX, int offsetY) const
if (mUsedTargetCursor)
mUsedTargetCursor->draw(graphics, px, py);
- // This is makes sure that actors positioned on the center of a tile have
- // their sprite aligned to the bottom of that tile, mainly to maintain
- // compatibility with older clients.
- if (mMap)
- py += mMap->getTileHeight() / 2;
-
return drawSpriteAt(graphics, px, py);
}
bool ActorSprite::drawSpriteAt(Graphics *graphics, int x, int y) const
{
+ y += paths.getIntValue("spriteOffsetY");
return mSprites.draw(graphics, x, y);
}
@@ -104,10 +93,7 @@ void ActorSprite::logic()
mChildParticleEffects.end());
// Move the remaining
- float py = mPos.y;
- if (mMap)
- py += mMap->getTileHeight() / 2; // See note at ActorSprite::draw
-
+ const float py = mPos.y + paths.getIntValue("spriteOffsetY");
for (Particle *p : mChildParticleEffects)
p->moveTo(mPos.x, py);
}
diff --git a/src/being.cpp b/src/being.cpp
index 9beb5355..6cb68994 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -839,12 +839,9 @@ void Being::logic()
{
updateMovement();
- // See note at ActorSprite::draw
- float py = mPos.y;
- if (mMap)
- py += mMap->getTileHeight() / 2;
-
// Update particle effects
+ const float py = mPos.y + paths.getIntValue("spriteOffsetY");
+
for (auto &spriteState : mSpriteStates)
for (auto &particle : spriteState.particles)
particle->moveTo(mPos.x, py);
diff --git a/src/defaults.cpp b/src/defaults.cpp
index dff06bbb..8a0f18a3 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -98,6 +98,11 @@ DefaultsData* getPathsDefaults()
AddDEF(pathsData, "hitEffectId", 26);
AddDEF(pathsData, "criticalHitEffectId", 28);
+ // This is makes sure that actors positioned on the center of a tile have
+ // their sprite aligned to the bottom of that tile. The default maintains
+ // compatibility with existing sprites.
+ AddDEF(pathsData, "spriteOffsetY", 16);
+
AddDEF(pathsData, "minimaps", "graphics/minimaps/");
AddDEF(pathsData, "maps", "maps/");
diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp
index 9858727d..dff87114 100644
--- a/src/gui/widgets/playerbox.cpp
+++ b/src/gui/widgets/playerbox.cpp
@@ -82,9 +82,8 @@ void PlayerBox::draw(gcn::Graphics *graphics)
if (mBeing)
{
// Draw character
- const int bs = getFrameSize();
- const int x = getWidth() / 2 + bs;
- const int y = getHeight() - bs;
+ const int x = getWidth() / 2;
+ const int y = (getHeight() + mBeing->getHeight()) / 2 - 12;
mBeing->drawSpriteAt(static_cast<Graphics*>(graphics), x, y);
}