pythonarcade / arcade

Easy to use Python library for creating 2D arcade games.
http://arcade.academy
Other
1.7k stars 322 forks source link

General Animation Class #1869

Open DragonMoffon opened 1 year ago

DragonMoffon commented 1 year ago

While working on some controllers for cameras, I started forumlating an idea for a general animation class.

I was going to add it to the Camera PR, but I realised it was a major scope creep.

Basically, I've written a while bunch of bezier (like photoshop pen tool) curves that are commonly used in animation. They take a number of points and a value from 0 to 1 (similar to easing functions). It returns an interpolated point. If mixed with easing methods, you get some extremely clean looking animations.

So my idea is you would have a queue of these curves and a callback method.

It was going to originally just be for cameras, but I realised I could generalize for any method that accepted the correct type.

Anyway, it'd be a big undertaking that would be fully backward compatible (I believe) so it can come in 3.1 or later.

Here are some more deets from Discord:

I propose we put together a generalised animator that uses a callback to change a 1D, 2D, and 3D value.

My idea for the callback is that you can use args and kwargs.

the args values you want passed at animation time to the callback (t value, curve info, delta_time, etc) while kwargs are constant values you want passed.

See issue #1869

DragonMoffon commented 1 year ago

Here is an idea on how to provide a callback system. It works with properties making it perfect for sprites.

class Animator2D:
  # All the implementation guff
  def set_property_callback(self, _instance: Any, _property: CorrectType ):
    def call_back(_value: Tuple[float, float]):
      _property.fset( _instance, _value )
    self._call_back = call_back

  def set_callback(self, _call_back: Callable[[Tuple[float, float]], Any]):
    self._call_back = _call_back