chrismweb

What would you use if you wanted to add a blink to happen randomly to an existing animation?

Like if I had a walk cycle, and I wanted to add a blink at a controlled interval (instead of like every 7/12 frames, be able to control when it happened)?

Likewise, if you had a bunch of different mouth shapes for talking, which you wanted to use regardless of which "body" animation he is currently doing?
사용자 아바타
chrismweb
  • 전체글: 135

Nate

For the mouths, put the images on the same slot, then change which mouth is shown programmatically (eg skeleton.setAttachment("mouthSlot", "mouthImage3");). As long as you don't key the mouth slot during animations, the animations won't affect the mouth slot.

For the blink, you could write code it just not draw the skeleton every X frames or time. If it is at an interval, you could generate an Animation.ColorTimeline programmatically to change a slot color:
Skeleton skeleton = ...;
Animation.ColorTimeline timeline = new Animation.ColorTimeline(2);
timeline.setSlotIndex(skeleton.findSlotIndex("some slot"));
timeline.setKeyframe(0, 0.5f, 1, 1, 1, 0);
timeline.setKeyframe(1, 0.75f, 1, 1, 1, 1);
// Add to existing animation (could also create a new Animation).
Animation animation = ...;
animation.getTimelines().add(timeline);
You can even use setCurve to control the interpolation. However if it is the whole skeleton, having a ColorTimeline for each slot is not super efficient. Some runtimes (libgdx) allow a color to be set for the skeleton. You could write your own timeline:
Animation.Timeline timeline = new Animation.Timeline() {
public void apply (Skeleton skeleton, float time, float alpha) {
skeleton.getColor().a = time > 0.5f && time < 0.75f ? 0 : 1;
}
};
Hmm I think I will refactor the Timeline interface slightly. :) It doesn't need getKeyframeCount.
사용자 아바타
Nate

Nate
  • 전체글: 11857

chrismweb

Awesome, thanks Nate!

The first method will work well for me for both things.

The second one, I may not have been clear with (or I can't wrap my head around it until I actually do it), I meant like eye blinking with slots(like the mouth), not the whole skeleton blinking/ color changing :D

Although I had no idea you could create animations like that - so if I could, I could probably make animations involving the blink (if it was 3 frames+ instead of 2), and just apply it to an existing animation.
Or (thinking much further ahead), eventually be able to keyframe lip sync sounds :D
사용자 아바타
chrismweb
  • 전체글: 135

Nate

For a random eye blink I would manage a timer (just a float that accumulates the frame delta time) and just set the attachment for the eyes slot to make the character blink.

As a result of typing the examples above, I refactored Timeline a little. It had getDuration and getKeyframeCount that weren't really necessary. Things are a bit cleaner now, for all runtimes.
사용자 아바타
Nate

Nate
  • 전체글: 11857


다시 돌아감: Editor