diff options
Diffstat (limited to 'src/sprite.cpp')
-rw-r--r-- | src/sprite.cpp | 19 |
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 | ||
59 | void Sprite::setWalking(bool walking) { | 54 | void 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 | ||
66 | void Sprite::updateAnimation() { | 61 | void 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 | ||