BUGFIX: Infinitely small motion on an axis after repeated key release;

read more

I've patched this issue by setting motion's elements to
CHARACTER_WALKING_SPEED or negative CHARACTER_WALKING_SPEED if they're
above or below zero, respectively.
This commit is contained in:
Kayne Ruse
2014-12-27 12:33:51 +11:00
parent 6c11aa0927
commit f2d517df9d
+18
View File
@@ -266,6 +266,7 @@ void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
if (motion.x != 0 && motion.y != 0) { if (motion.x != 0 && motion.y != 0) {
motion *= CHARACTER_WALKING_MOD; motion *= CHARACTER_WALKING_MOD;
} }
//set the info
localCharacter->SetMotion(motion); localCharacter->SetMotion(motion);
localCharacter->CorrectSprite(); localCharacter->CorrectSprite();
SendLocalCharacterMotion(); SendLocalCharacterMotion();
@@ -291,7 +292,24 @@ void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED); motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED);
break; break;
} }
//BUGFIX: reset cardinal direction speed on key release
if (motion.x > 0) {
motion.x = CHARACTER_WALKING_SPEED;
}
else if (motion.x < 0) {
motion.x = -CHARACTER_WALKING_SPEED;
}
if (motion.y > 0) {
motion.y = CHARACTER_WALKING_SPEED;
}
else if (motion.y < 0) {
motion.y = -CHARACTER_WALKING_SPEED;
}
//handle diagonals //handle diagonals
if (motion.x != 0 && motion.y != 0) {
motion *= CHARACTER_WALKING_MOD;
}
//set the info
localCharacter->SetMotion(motion); localCharacter->SetMotion(motion);
localCharacter->CorrectSprite(); localCharacter->CorrectSprite();
SendLocalCharacterMotion(); SendLocalCharacterMotion();