mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 15:24:55 +08:00
Events list is now required.
Simplifies applying the event timeline and isn't hard to supply.
This commit is contained in:
parent
6f1fbb004d
commit
45c3487098
@ -54,8 +54,16 @@ typedef struct {
|
||||
Animation* Animation_create (const char* name, int timelineCount);
|
||||
void Animation_dispose (Animation* self);
|
||||
|
||||
/** Poses the skeleton at the specified time for this animation.
|
||||
* @param lastTime The last time the animation was applied.
|
||||
* @param events Any triggered events are added. */
|
||||
void Animation_apply (const Animation* self, struct Skeleton* skeleton, float lastTime, float time, int loop,
|
||||
Event** events, int* eventCount);
|
||||
|
||||
/** Poses the skeleton at the specified time for this animation mixed with the current pose.
|
||||
* @param lastTime The last time the animation was applied.
|
||||
* @param events Any triggered events are added.
|
||||
* @param alpha The amount of this animation that affects the current pose. */
|
||||
void Animation_mix (const Animation* self, struct Skeleton* skeleton, float lastTime, float time, int loop, Event** events,
|
||||
int* eventCount, float alpha);
|
||||
|
||||
|
||||
@ -522,7 +522,7 @@ void _EventTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float l
|
||||
/* Fire events after last time for looped animations. */
|
||||
_EventTimeline_apply(timeline, skeleton, lastTime, (float)INT_MAX, firedEvents, eventCount, alpha);
|
||||
lastTime = 0;
|
||||
} else if (lastTime >= self->frames[self->framesLength - 1]) return; /* Last time is after last frame. */
|
||||
}
|
||||
|
||||
if (lastTime <= self->frames[0] || self->framesLength == 1)
|
||||
frameIndex = 0;
|
||||
|
||||
@ -52,14 +52,9 @@ namespace Spine {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public void Apply (Skeleton skeleton, float time, bool loop) {
|
||||
Apply(skeleton, time, time, loop, null);
|
||||
}
|
||||
|
||||
/// <summary>Poses the skeleton at the specified time for this animation.</summary>
|
||||
/// <param name="lastTime The last time the animation was applied. Can be equal to time if events shouldn't be fired.</param>
|
||||
/// <param name="events Any triggered events are added. May be null if lastTime is known to not cause any events to trigger.</param>
|
||||
/// <param name="lastTime">The last time the animation was applied.</param>
|
||||
/// <param name="events">Any triggered events are added.</param>
|
||||
public void Apply (Skeleton skeleton, float lastTime, float time, bool loop, List<Event> events) {
|
||||
if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null.");
|
||||
|
||||
@ -73,15 +68,10 @@ namespace Spine {
|
||||
timelines[i].Apply(skeleton, lastTime, time, events, 1);
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public void Mix (Skeleton skeleton, float time, bool loop, float alpha) {
|
||||
Mix(skeleton, time, time, loop, null, alpha);
|
||||
}
|
||||
|
||||
/// <summary>Poses the skeleton at the specified time for this animation mixed with the current pose.</summary>
|
||||
/// <param name="lastTime The last time the animation was applied. Can be equal to time if events shouldn't be fired.</param>
|
||||
/// <param name="events Any triggered events are added. May be null if lastTime is known to not cause any events to trigger.</param>
|
||||
/// <param name="alpha The amount of this animation that affects the current pose.</param>
|
||||
/// <param name="lastTime">The last time the animation was applied.</param>
|
||||
/// <param name="events">Any triggered events are added.</param>
|
||||
/// <param name="alpha">The amount of this animation that affects the current pose.</param>
|
||||
public void Mix (Skeleton skeleton, float lastTime, float time, bool loop, List<Event> events, float alpha) {
|
||||
if (skeleton == null) throw new ArgumentNullException("skeleton cannot be null.");
|
||||
|
||||
@ -476,7 +466,7 @@ namespace Spine {
|
||||
if (lastTime > time) { // Fire events after last time for looped animations.
|
||||
Apply(skeleton, lastTime, int.MaxValue, firedEvents, alpha);
|
||||
lastTime = 0;
|
||||
} else if (lastTime >= frames[frameCount - 1]) return; // Last time is after last frame.
|
||||
}
|
||||
|
||||
int frameIndex;
|
||||
if (lastTime <= frames[0] || frameCount == 1)
|
||||
|
||||
@ -63,14 +63,9 @@ public class Animation {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
public void apply (Skeleton skeleton, float time, boolean loop) {
|
||||
apply(skeleton, time, time, loop, null);
|
||||
}
|
||||
|
||||
/** Poses the skeleton at the specified time for this animation.
|
||||
* @param lastTime The last time the animation was applied. Can be equal to time if events shouldn't be fired.
|
||||
* @param events Any triggered events are added. May be null if lastTime is known to not cause any events to trigger. */
|
||||
* @param lastTime The last time the animation was applied.
|
||||
* @param events Any triggered events are added. */
|
||||
public void apply (Skeleton skeleton, float lastTime, float time, boolean loop, Array<Event> events) {
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
|
||||
@ -84,14 +79,9 @@ public class Animation {
|
||||
timelines.get(i).apply(skeleton, lastTime, time, events, 1);
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
public void mix (Skeleton skeleton, float time, boolean loop, float alpha) {
|
||||
mix(skeleton, time, time, loop, null, alpha);
|
||||
}
|
||||
|
||||
/** Poses the skeleton at the specified time for this animation mixed with the current pose.
|
||||
* @param lastTime The last time the animation was applied. Can be equal to time if events shouldn't be fired.
|
||||
* @param events Any triggered events are added. May be null if lastTime is known to not cause any events to trigger.
|
||||
* @param lastTime The last time the animation was applied.
|
||||
* @param events Any triggered events are added.
|
||||
* @param alpha The amount of this animation that affects the current pose. */
|
||||
public void mix (Skeleton skeleton, float lastTime, float time, boolean loop, Array<Event> events, float alpha) {
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
@ -550,7 +540,7 @@ public class Animation {
|
||||
if (lastTime > time) { // Fire events after last time for looped animations.
|
||||
apply(skeleton, lastTime, Integer.MAX_VALUE, firedEvents, alpha);
|
||||
lastTime = 0;
|
||||
} else if (lastTime >= frames[frameCount - 1]) return; // Last time is after last frame.
|
||||
}
|
||||
|
||||
int frameIndex;
|
||||
if (lastTime <= frames[0] || frameCount == 1)
|
||||
|
||||
@ -58,6 +58,7 @@ import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
|
||||
import com.badlogic.gdx.physics.box2d.FixtureDef;
|
||||
import com.badlogic.gdx.physics.box2d.PolygonShape;
|
||||
import com.badlogic.gdx.physics.box2d.World;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
public class Box2DExample extends ApplicationAdapter {
|
||||
SpriteBatch batch;
|
||||
@ -68,6 +69,7 @@ public class Box2DExample extends ApplicationAdapter {
|
||||
Skeleton skeleton;
|
||||
Animation animation;
|
||||
float time;
|
||||
Array<Event> events = new Array();
|
||||
|
||||
OrthographicCamera camera;
|
||||
Box2DDebugRenderer box2dRenderer;
|
||||
@ -146,7 +148,7 @@ public class Box2DExample extends ApplicationAdapter {
|
||||
batch.setTransformMatrix(camera.view);
|
||||
batch.begin();
|
||||
|
||||
animation.apply(skeleton, time, true);
|
||||
animation.apply(skeleton, time, time, true, events);
|
||||
skeleton.x += 8 * delta;
|
||||
skeleton.updateWorldTransform();
|
||||
skeletonRenderer.draw(batch, skeleton);
|
||||
|
||||
@ -39,10 +39,13 @@ import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
|
||||
import com.badlogic.gdx.graphics.GL10;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
public class MixTest extends ApplicationAdapter {
|
||||
SpriteBatch batch;
|
||||
float time;
|
||||
Array<Event> events = new Array();
|
||||
|
||||
SkeletonRenderer renderer;
|
||||
SkeletonRendererDebug debugRenderer;
|
||||
|
||||
@ -103,21 +106,21 @@ public class MixTest extends ApplicationAdapter {
|
||||
skeleton.setX(-50);
|
||||
} else if (time > beforeJump + jump) {
|
||||
// just walk after jump
|
||||
walkAnimation.apply(skeleton, time, true);
|
||||
walkAnimation.apply(skeleton, time, time, true, events);
|
||||
} else if (time > blendOutStart) {
|
||||
// blend out jump
|
||||
walkAnimation.apply(skeleton, time, true);
|
||||
jumpAnimation.mix(skeleton, time - beforeJump, false, 1 - (time - blendOutStart) / blendOut);
|
||||
walkAnimation.apply(skeleton, time, time, true, events);
|
||||
jumpAnimation.mix(skeleton, time - beforeJump, time - beforeJump, false, events, 1 - (time - blendOutStart) / blendOut);
|
||||
} else if (time > beforeJump + blendIn) {
|
||||
// just jump
|
||||
jumpAnimation.apply(skeleton, time - beforeJump, false);
|
||||
jumpAnimation.apply(skeleton, time - beforeJump, time - beforeJump, false, events);
|
||||
} else if (time > beforeJump) {
|
||||
// blend in jump
|
||||
walkAnimation.apply(skeleton, time, true);
|
||||
jumpAnimation.mix(skeleton, time - beforeJump, false, (time - beforeJump) / blendIn);
|
||||
walkAnimation.apply(skeleton, time, time, true, events);
|
||||
jumpAnimation.mix(skeleton, time - beforeJump, time - beforeJump, false, events, (time - beforeJump) / blendIn);
|
||||
} else {
|
||||
// just walk before jump
|
||||
walkAnimation.apply(skeleton, time, true);
|
||||
walkAnimation.apply(skeleton, time, time, true, events);
|
||||
}
|
||||
|
||||
skeleton.updateWorldTransform();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user