spine-unity, added flip timelines.

This commit is contained in:
NathanSweet 2014-10-02 18:09:38 +02:00
parent 60ab9d5fa8
commit 08a680c972
2 changed files with 66 additions and 1 deletions

View File

@ -216,7 +216,7 @@ namespace Spine {
public RotateTimeline (int frameCount)
: base(frameCount) {
frames = new float[frameCount * 2];
frames = new float[frameCount << 1];
}
/// <summary>Sets the time and value of the specified keyframe.</summary>
@ -669,4 +669,50 @@ namespace Spine {
ikConstraint.bendDirection = (int)frames[frameIndex + PREV_FRAME_BEND_DIRECTION];
}
}
public class FlipXTimeline : CurveTimeline {
internal float[] frames;
public float[] Frames { get { return frames; } set { frames = value; } } // time, flip, ...
public FlipXTimeline (int frameCount)
: base(frameCount) {
frames = new float[frameCount << 1];
}
/// <summary>Sets the time and value of the specified keyframe.</summary>
public void SetFrame (int frameIndex, float time, bool flip) {
frameIndex *= 2;
frames[frameIndex] = time;
frames[frameIndex + 1] = flip ? 1 : 0;
}
override public void Apply (Skeleton skeleton, float lastTime, float time, List<Event> firedEvents, float alpha) {
float[] frames = this.frames;
if (time < frames[0]) {
if (lastTime > time) Apply(skeleton, lastTime, int.MaxValue, null, 0);
return;
} else if (lastTime > time) //
lastTime = -1;
int frameIndex = (time >= frames[frames.Length - 2] ? frames.Length : Animation.binarySearch(frames, time, 2)) - 2;
if (frames[frameIndex] <= lastTime) return;
Flip(skeleton, frames[frameIndex + 1] != 0);
}
virtual protected void Flip (Skeleton skeleton, bool flip) {
skeleton.flipX = flip;
}
}
public class FlipYTimeline : FlipXTimeline {
public FlipYTimeline (int frameCount)
: base(frameCount) {
}
override protected void Flip (Skeleton skeleton, bool flip) {
skeleton.flipY = flip;
}
}
}

View File

@ -550,6 +550,25 @@ namespace Spine {
}
}
if (map.ContainsKey("flipx")) {
var flipMap = (List<Object>)map["flipx"];
var timeline = new FlipXTimeline(flipMap.Count);
int frameIndex = 0;
foreach (Dictionary<String, Object> valueMap in flipMap)
timeline.SetFrame(frameIndex++, (float)valueMap["time"], valueMap.ContainsKey("x") ? (bool)valueMap["x"] : false);
timelines.Add(timeline);
duration = Math.Max(duration, timeline.frames[timeline.FrameCount * 2 - 2]);
}
if (map.ContainsKey("flipy")) {
var flipMap = (List<Object>)map["flipy"];
var timeline = new FlipYTimeline(flipMap.Count);
int frameIndex = 0;
foreach (Dictionary<String, Object> valueMap in flipMap)
timeline.SetFrame(frameIndex++, (float)valueMap["time"], valueMap.ContainsKey("y") ? (bool)valueMap["y"] : false);
timelines.Add(timeline);
duration = Math.Max(duration, timeline.frames[timeline.FrameCount * 2 - 2]);
}
if (map.ContainsKey("draworder")) {
var values = (List<Object>)map["draworder"];
var timeline = new DrawOrderTimeline(values.Count);