I’m creating a Pygame helper library, and one thing I’ve implemented is an Animator
, which can ease any numerical attribute between two values.
To add an ‘animation’ to my Animator
, you call:
animator.addAnimation(object, attribute, newValue, duration=1, easingFunction=easeLinear, type=float)
The reason for passing both the object and the string attribute name is because my implementation uses getattr
and setattr
.
My question: is there any way for me to simply pass the attribute directly to my addAnimation
method and then determine the object name and the string attribute behind the scenes?
i.e. I’d like to be able to simply call:
animator.addAnimation(sprite.position.x, ...)
rather than
animator.addAnimation(sprite.position, 'x', ...)
Happy to do things a different/better way if there is one. My main requirement is for the API to be as intuitive as possible.
Thanks.
2
No. A function argument is just an expression that gets evaluated down to a single value, which then gets passed to the function. There’s no way for the function to know which variable, attributes, or operations the value comes from.