I was wondering how you all handle material property animation. Let’s say I want to indicate that the character is hurt by interpolating the Lighting material’s diffuse color to red and back to a default value in 0.8f seconds.
How do you all do this property animation? Let’s discuss and I’m curious about your solutions.
I usually write a control something like HurtControl, and extract material in setSpatial() method and then do the interpolation with an EaseFunction in controlUpdate. When iterpolation is done, the control removes itself.
I have an animator appstate that handles all animations, spatial transformations, materials, variables it handles everything.
The animations are imported trough the asset manager, completely separated from the actual models. That comes with downsides when it comes to organizing assets.
I then basically call.
Animator.animate("Blink", Spatial, 0.8)
It allows to query for animation states too, so i can have a simple state machine that handles the actual calls.
Or a control, or whatever
For one-off “UI-specific” stuff, I use Lemur’s animation state.
For anything else it’s usually just a visualization of the state of the object.
Yours kind of falls between this in a way… since it’s a temporary UI-specific ‘time based hit indicator’… rather than “HP is low” style visualization of object state.
In your case, I might be tempted to use AnimationState. It would not be hard to write a color tween… but there is also the existing “call method” tweens that could be used in a pinch. Tweens (lemur 1.15.0 API)…-
Nothing wrong with your approach to use a custom control, either.
Note: if you are setting the material parameter every time then you can avoid that by setting the ColorRGBA once and just interpolating that. JME resends the material values every frame even if you haven’t called setParameter again.