summary refs log tree commit diff stats
path: root/src/sprite.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-01-30 14:43:41 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-01-30 14:43:41 -0500
commit8a38699f399103d4ee003e6eb63dd62656115be2 (patch)
tree765a62bacc24d8a4c57ea56915de6731294c824b /src/sprite.cpp
parent2c91a60b5fd79aa2c978ce4496a068f15a4df5cc (diff)
downloadtanetane-8a38699f399103d4ee003e6eb63dd62656115be2.tar.gz
tanetane-8a38699f399103d4ee003e6eb63dd62656115be2.tar.bz2
tanetane-8a38699f399103d4ee003e6eb63dd62656115be2.zip
Sprite animations are more generic than still/walk now
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