diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-12-29 23:15:54 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-12-29 23:15:54 +0000 |
commit | 82a0eab42381e89803d93f6ae1a9cfafd2abb254 (patch) | |
tree | 12e7f46ca4f8060626c595c17ffb2c71151cb7cd /src/being.cpp | |
parent | 787f53c8dcd799161bd9a662dc2fe898f1708361 (diff) | |
download | mana-82a0eab42381e89803d93f6ae1a9cfafd2abb254.tar.gz mana-82a0eab42381e89803d93f6ae1a9cfafd2abb254.tar.bz2 mana-82a0eab42381e89803d93f6ae1a9cfafd2abb254.tar.xz mana-82a0eab42381e89803d93f6ae1a9cfafd2abb254.zip |
Improved movement smoothness by avoiding useless changes of sprite direction.
Diffstat (limited to 'src/being.cpp')
-rw-r--r-- | src/being.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/being.cpp b/src/being.cpp index 9cd0af0d..55a321ab 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -60,7 +60,7 @@ Being::Being(Uint16 id, Uint16 job, Map *map): mWeapon(0), mWalkSpeed(150), mSpeedModifier(1024), - mDirection(DOWN), + mOldDirection(DOWN), mDirection(DOWN), mMap(NULL), mHairStyle(0), mHairColor(0), mSpeechTime(0), @@ -368,6 +368,9 @@ Being::setAction(Uint8 action) void Being::setDirection(Uint8 direction) { + if (mDirection == direction) + return; + mOldDirection = mDirection; mDirection = direction; SpriteDirection dir = getSpriteDirection(); @@ -383,7 +386,25 @@ Being::getSpriteDirection() const { SpriteDirection dir; - if (mDirection & UP) + // if the direction has not changed much, keep it for the sprite + if (mOldDirection & mDirection & UP) + { + dir = DIRECTION_UP; + } + else if (mOldDirection & mDirection & RIGHT) + { + dir = DIRECTION_RIGHT; + } + else if (mOldDirection & mDirection & DOWN) + { + dir = DIRECTION_DOWN; + } + else if (mOldDirection & mDirection & LEFT) + { + dir = DIRECTION_LEFT; + } + // otherwise, use only the new direction + else if (mDirection & UP) { dir = DIRECTION_UP; } @@ -395,7 +416,8 @@ Being::getSpriteDirection() const { dir = DIRECTION_DOWN; } - else { + else + { dir = DIRECTION_LEFT; } |