def _animate(self, name, value, duration=.1, curve=curve.in_expo, loop=False, resolution=None, interrupt=True, time_step=None, auto_destroy=True): animator_name = name + '_animator' # print('start animating value:', name, animator_name ) if interrupt and hasattr(self, animator_name): getattr(self, animator_name).pause() # print('interrupt', animator_name) else: try: getattr(self, animator_name).finish() except: pass setattr(self, animator_name, Sequence(loop=loop, time_step=time_step, auto_destroy=auto_destroy)) sequence = getattr(self, animator_name) self.animations.append(sequence) # sequence.append(Wait(delay)) if not resolution: resolution = max(int(duration * 60), 1) for i in range(resolution+1): t = i / resolution # if isinstance(curve, CubicBezier): # t = curve.calculate(t) # else: t = curve(t) sequence.append(Wait(duration / resolution)) sequence.append(Func(setattr, self, name, lerp(getattr(self, name), value, t))) sequence.start() return sequence
def _animate(self, name, value, duration=.1, curve=curve.in_expo, resolution=None, interrupt=True): animator_name = name + '_animator' # print('start animating value:', name, animator_name ) if interrupt and hasattr(self, animator_name): try: getattr(self, animator_name).pause() # print('interrupt', animator_name) except: pass else: try: getattr(self, animator_name).finish() except: pass setattr(self, animator_name, Sequence()) sequence = getattr(self, animator_name) self.animations.append(sequence) # sequence.append(Wait(delay)) if not resolution: resolution = max(int(duration * 60), 1) for i in range(resolution+1): t = i / resolution t = curve(t) sequence.append(Wait(duration / resolution)) sequence.append(Func(setattr, self, name, lerp(getattr(self, name), value, t))) sequence.start() return sequence
def animate(self, name, value, duration=.1, delay=0, curve=curve.in_expo, loop=False, resolution=None, interrupt='kill', time_step=None, auto_destroy=True): if duration == 0 and delay == 0: setattr(self, name, value) return None if delay: from ursina.ursinastuff import invoke return invoke(self.animate, name, value, duration=duration, curve=curve, loop=loop, resolution=resolution, time_step=time_step, auto_destroy=auto_destroy, delay=delay) animator_name = name + '_animator' # print('start animating value:', name, animator_name ) if interrupt and hasattr(self, animator_name): getattr(getattr(self, animator_name), interrupt)( ) # call kill() or finish() depending on what the interrupt value is. # print('interrupt', interrupt, animator_name) sequence = Sequence(loop=loop, time_step=time_step, auto_destroy=auto_destroy) setattr(self, animator_name, sequence) self.animations.append(sequence) if not resolution: resolution = max(int(duration * 60), 1) for i in range(resolution + 1): t = i / resolution t = curve(t) sequence.append(Wait(duration / resolution)) sequence.append( Func(setattr, self, name, lerp(getattr(self, name), value, t))) sequence.start() return sequence