Skip to content

Commit 7c4f9f2

Browse files
committed
Fixed bug with animation not playing when called multiple times.
1 parent df029d3 commit 7c4f9f2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/core/scripting/python/python_modules.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,15 +1067,17 @@ PyObject* PythonModules::animated_sprite_play(PyObject *self, PyObject *args, Py
10671067
if (PyArg_ParseTupleAndKeywords(args, kwargs, "is", animatedSpriteAnimationUpdateKWList, &entity, &pyAnimationName)) {
10681068
AnimatedSpriteComponent animatedSpriteComponent = entityComponentOrchestrator->GetComponent<AnimatedSpriteComponent>(entity);
10691069
const std::string &animationName = std::string(pyAnimationName);
1070-
if (animationName.empty()) {
1071-
animatedSpriteComponent.isPlaying = true;
1072-
animatedSpriteComponent.startAnimationTickTime = SDL_GetTicks();
1073-
} else if (animatedSpriteComponent.animations.count(animationName) > 0) {
1074-
animatedSpriteComponent.isPlaying = true;
1075-
animatedSpriteComponent.currentAnimation = animatedSpriteComponent.animations[animationName];
1076-
animatedSpriteComponent.startAnimationTickTime = SDL_GetTicks();
1070+
if (!animatedSpriteComponent.isPlaying || animatedSpriteComponent.currentAnimation.name != animationName) {
1071+
if (animationName.empty()) {
1072+
animatedSpriteComponent.isPlaying = true;
1073+
animatedSpriteComponent.startAnimationTickTime = SDL_GetTicks();
1074+
} else if (animatedSpriteComponent.animations.count(animationName) > 0) {
1075+
animatedSpriteComponent.isPlaying = true;
1076+
animatedSpriteComponent.currentAnimation = animatedSpriteComponent.animations[animationName];
1077+
animatedSpriteComponent.startAnimationTickTime = SDL_GetTicks();
1078+
}
1079+
entityComponentOrchestrator->UpdateComponent<AnimatedSpriteComponent>(entity, animatedSpriteComponent);
10771080
}
1078-
entityComponentOrchestrator->UpdateComponent<AnimatedSpriteComponent>(entity, animatedSpriteComponent);
10791081
Py_RETURN_NONE;
10801082
}
10811083
return nullptr;

0 commit comments

Comments
 (0)