diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-02-12 16:25:24 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-02-12 22:12:24 +0100 |
commit | 6bb16f951b460c6378dbf1b5d39acfd64eb81354 (patch) | |
tree | 79af508017e7665cb9e1c624e27b44f5e82230e9 /src | |
parent | 9d2f44ee9c2a026d353c00836441f1c47b3dfa33 (diff) | |
download | mana-client-6bb16f951b460c6378dbf1b5d39acfd64eb81354.tar.gz mana-client-6bb16f951b460c6378dbf1b5d39acfd64eb81354.tar.bz2 mana-client-6bb16f951b460c6378dbf1b5d39acfd64eb81354.tar.xz mana-client-6bb16f951b460c6378dbf1b5d39acfd64eb81354.zip |
Fixes to actor drawing order
On the fringe layer, actors are drawn 'sorted' together with the tiles. When
the sorting order was separated from the actual Y position of the actor, the
tile drawing loop was not adapted to take this drawOrder into account rather
than the plain Y position.
Also, ActorSprite::draw was applying a half-tile offset to position the sprite
at the bottom while the logical position of the actor is at the center of the
tile. However, it failed to override getDrawOrder to account for this offset,
causing actors to get drawn earlier than they should (and thus being overlapped
by fringe layer tiles when they actually shouldn't).
This fixes drawing glitches with the paths around Hurnscald and reduces the
glitches when walking up/down through grass.
Reviewed-by: Erik Schilling
Diffstat (limited to 'src')
-rw-r--r-- | src/actorsprite.cpp | 30 | ||||
-rw-r--r-- | src/actorsprite.h | 2 | ||||
-rw-r--r-- | src/map.cpp | 2 |
3 files changed, 22 insertions, 12 deletions
diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index c71c183d..3b3a83ef 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -23,7 +23,6 @@ #include "client.h" #include "configuration.h" #include "event.h" -#include "game.h" #include "imagesprite.h" #include "localplayer.h" #include "log.h" @@ -67,6 +66,17 @@ ActorSprite::~ActorSprite() event.trigger(Event::ActorSpriteChannel); } +int ActorSprite::getDrawOrder() const +{ + int drawOrder = Actor::getDrawOrder(); + + // See note at ActorSprite::draw + if (mMap) + drawOrder += mMap->getTileHeight() / 2; + + return drawOrder; +} + bool ActorSprite::draw(Graphics *graphics, int offsetX, int offsetY) const { int px = getPixelX() + offsetX; @@ -79,11 +89,11 @@ bool ActorSprite::draw(Graphics *graphics, int offsetX, int offsetY) const mUsedTargetCursor->draw(graphics, px, py); } - Map *map = Game::instance() ? Game::instance()->getCurrentMap() : 0; - if (map) - { - py += map->getTileHeight() / 2; - } + // 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); } @@ -111,12 +121,10 @@ void ActorSprite::logic() } } - Map *map = Game::instance() ? Game::instance()->getCurrentMap() : 0; + // See note at ActorSprite::draw float py = mPos.y; - if (map) - { - py += (float)map->getTileHeight() / 2; - } + if (mMap) + py += mMap->getTileHeight() / 2; // Update particle effects mChildParticleEffects.moveTo(mPos.x, py); diff --git a/src/actorsprite.h b/src/actorsprite.h index cb9ea851..ab327e16 100644 --- a/src/actorsprite.h +++ b/src/actorsprite.h @@ -75,6 +75,8 @@ public: */ virtual Type getType() const { return UNKNOWN; } + virtual int getDrawOrder() const; + virtual bool draw(Graphics *graphics, int offsetX, int offsetY) const; virtual bool drawSpriteAt(Graphics *graphics, int x, int y) const; diff --git a/src/map.cpp b/src/map.cpp index 89bcf061..8c748bbc 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -150,7 +150,7 @@ void MapLayer::draw(Graphics *graphics, // tiles have been drawn if (mIsFringeLayer) { - while (ai != actors.end() && (*ai)->getPixelY() + while (ai != actors.end() && (*ai)->getDrawOrder() <= y * mMap->getTileHeight()) { (*ai)->draw(graphics, -scrollX, -scrollY); |