summary refs log tree commit diff stats
path: root/src/sprite.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/sprite.cpp')
-rw-r--r--src/sprite.cpp19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/sprite.cpp b/src/sprite.cpp index cc196ae..c52807a 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp
@@ -38,12 +38,7 @@ Sprite::Sprite(std::string_view filename, Renderer& renderer) {
38 animations_.push_back(std::move(frames)); 38 animations_.push_back(std::move(frames));
39 39
40 Direction dir = directionFromString(std::string(m[2])); 40 Direction dir = directionFromString(std::string(m[2]));
41 41 stateDirToAnim_[m[1]][dir] = animId;
42 if (m[1] == "still") {
43 stillAnims_[dir] = animId;
44 } else {
45 walkingAnims_[dir] = animId;
46 }
47 } 42 }
48 43
49 updateAnimation(); 44 updateAnimation();
@@ -56,19 +51,15 @@ void Sprite::setDirection(Direction dir) {
56 } 51 }
57} 52}
58 53
59void Sprite::setWalking(bool walking) { 54void Sprite::setState(std::string state) {
60 if (isWalking_ != walking) { 55 if (state_ != state) {
61 isWalking_ = walking; 56 state_ = state;
62 updateAnimation(); 57 updateAnimation();
63 } 58 }
64} 59}
65 60
66void Sprite::updateAnimation() { 61void Sprite::updateAnimation() {
67 if (isWalking_) { 62 curAnim_ = stateDirToAnim_[state_][curDir_];
68 curAnim_ = walkingAnims_[curDir_];
69 } else {
70 curAnim_ = stillAnims_[curDir_];
71 }
72 curFrame_ = 0; 63 curFrame_ = 0;
73} 64}
74 65