Skip to content

Commit

Permalink
made Animator also start the entity's animations.
Browse files Browse the repository at this point in the history
  • Loading branch information
pokepetter committed Mar 19, 2024
1 parent 361b685 commit 5507349
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions ursina/prefabs/animator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@


class Animator():
def __init__(self, animations=None, start_state=''):
def __init__(self, animations=None, start_state='', pause_disabled=True):

self.animations = animations # dict
self.pause_disabled = pause_disabled

if not start_state and self.animations:
start_state = list(self.animations)[0]
Expand All @@ -27,14 +28,19 @@ def state(self, value):

elif not self._state == value:
# only show set state and disable the rest
for key, anim in self.animations.items():
if anim:
anim.enabled = value == key

anim = self.animations[value]
if hasattr(anim, 'start') and callable(anim.start):
# print('start', anim)
anim.start()
for name, entity in self.animations.items():
if entity:
entity.enabled = value == name
if self.pause_disabled and hasattr(entity, 'pause') and not entity.enabled:
[anim.pause() for anim in entity.animations]

entity = self.animations[value]
if entity:
if hasattr(entity, 'start') and callable(entity.start):
entity.start()

if hasattr(entity, 'animations'):
[anim.start() for anim in entity.animations]

self._state = value

Expand Down

0 comments on commit 5507349

Please sign in to comment.