From 45c34870986f0f8a28d4ea5cb59ae985d0a79ab5 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Wed, 2 Oct 2013 14:10:55 +0200 Subject: [PATCH] Events list is now required. Simplifies applying the event timeline and isn't hard to supply. --- spine-c/include/spine/Animation.h | 8 +++++++ spine-c/src/spine/Animation.c | 2 +- spine-csharp/src/Animation.cs | 22 +++++-------------- .../com/esotericsoftware/spine/Animation.java | 20 +++++------------ .../esotericsoftware/spine/Box2DExample.java | 4 +++- .../com/esotericsoftware/spine/MixTest.java | 17 ++++++++------ 6 files changed, 33 insertions(+), 40 deletions(-) diff --git a/spine-c/include/spine/Animation.h b/spine-c/include/spine/Animation.h index 16862fa32..21d8ed80d 100644 --- a/spine-c/include/spine/Animation.h +++ b/spine-c/include/spine/Animation.h @@ -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); diff --git a/spine-c/src/spine/Animation.c b/spine-c/src/spine/Animation.c index a1503de57..bcf257724 100644 --- a/spine-c/src/spine/Animation.c +++ b/spine-c/src/spine/Animation.c @@ -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; diff --git a/spine-csharp/src/Animation.cs b/spine-csharp/src/Animation.cs index ea2688299..8aca5e5c8 100644 --- a/spine-csharp/src/Animation.cs +++ b/spine-csharp/src/Animation.cs @@ -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); - } - /// Poses the skeleton at the specified time for this animation. - /// + /// The last time the animation was applied. + /// Any triggered events are added. public void Apply (Skeleton skeleton, float lastTime, float time, bool loop, List 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); - } - /// Poses the skeleton at the specified time for this animation mixed with the current pose. - /// - /// The last time the animation was applied. + /// Any triggered events are added. + /// The amount of this animation that affects the current pose. public void Mix (Skeleton skeleton, float lastTime, float time, bool loop, List 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) diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java index 651f6e8a1..34d0a99f1 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java @@ -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 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 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) diff --git a/spine-libgdx/test/com/esotericsoftware/spine/Box2DExample.java b/spine-libgdx/test/com/esotericsoftware/spine/Box2DExample.java index 381fc5858..0c85b0673 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/Box2DExample.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/Box2DExample.java @@ -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 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); diff --git a/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java b/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java index 5a85d11a9..ecb2b5cbc 100644 --- a/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java +++ b/spine-libgdx/test/com/esotericsoftware/spine/MixTest.java @@ -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 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();