mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Event timeline fixed to fire events correctly for edge cases.
This commit is contained in:
parent
e2fccf72d6
commit
8883f73a10
@ -1,15 +1,23 @@
|
|||||||
/*******************************************************************************
|
/******************************************************************************
|
||||||
|
* Spine Runtime Software License - Version 1.0
|
||||||
|
*
|
||||||
* Copyright (c) 2013, Esoteric Software
|
* Copyright (c) 2013, Esoteric Software
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms in whole or in part, with
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* or without modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
* 1. A Spine Single User License or Spine Professional License must be
|
||||||
* list of conditions and the following disclaimer.
|
* purchased from Esoteric Software and the license must remain valid:
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
* http://esotericsoftware.com/
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* 2. Redistributions of source code must retain this license, which is the
|
||||||
* and/or other materials provided with the distribution.
|
* above copyright notice, this declaration of conditions and the following
|
||||||
|
* disclaimer.
|
||||||
|
* 3. Redistributions in binary form must reproduce this license, which is the
|
||||||
|
* above copyright notice, this declaration of conditions and the following
|
||||||
|
* disclaimer, in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
@ -21,7 +29,7 @@
|
|||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
******************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
package com.esotericsoftware.spine;
|
package com.esotericsoftware.spine;
|
||||||
|
|
||||||
@ -66,8 +74,8 @@ public class Animation {
|
|||||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||||
|
|
||||||
if (loop && duration != 0) {
|
if (loop && duration != 0) {
|
||||||
lastTime %= duration;
|
|
||||||
time %= duration;
|
time %= duration;
|
||||||
|
lastTime %= duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array<Timeline> timelines = this.timelines;
|
Array<Timeline> timelines = this.timelines;
|
||||||
@ -539,14 +547,24 @@ public class Animation {
|
|||||||
int frameCount = frames.length;
|
int frameCount = frames.length;
|
||||||
if (lastTime >= frames[frameCount - 1]) return; // Last time is after last frame.
|
if (lastTime >= frames[frameCount - 1]) return; // Last time is after last frame.
|
||||||
|
|
||||||
|
if (lastTime > time) {
|
||||||
|
// Fire events after last time for looped animations.
|
||||||
|
apply(skeleton, lastTime, Integer.MAX_VALUE, alpha, firedEvents);
|
||||||
|
lastTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
int frameIndex;
|
int frameIndex;
|
||||||
if (frameCount == 1)
|
if (frameCount == 1)
|
||||||
frameIndex = 0;
|
frameIndex = 0;
|
||||||
else {
|
else {
|
||||||
frameIndex = binarySearch(frames, lastTime, 1);
|
frameIndex = binarySearch(frames, lastTime, 1);
|
||||||
float frame = frames[frameIndex];
|
float frame = frames[frameIndex];
|
||||||
while (frameIndex > 0 && frame == frames[frameIndex - 1])
|
while (frameIndex > 0) {
|
||||||
frameIndex--; // Fire multiple events with the same frame.
|
float lastFrame = frames[frameIndex - 1];
|
||||||
|
// Fire multiple events with the same frame and events that occurred at lastTime.
|
||||||
|
if (lastFrame != frame && lastFrame != lastTime) break;
|
||||||
|
frameIndex--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (; frameIndex < frameCount && time > frames[frameIndex]; frameIndex++)
|
for (; frameIndex < frameCount && time > frames[frameIndex]; frameIndex++)
|
||||||
firedEvents.add(events[frameIndex]);
|
firedEvents.add(events[frameIndex]);
|
||||||
|
|||||||
@ -1,15 +1,23 @@
|
|||||||
/*******************************************************************************
|
/******************************************************************************
|
||||||
|
* Spine Runtime Software License - Version 1.0
|
||||||
|
*
|
||||||
* Copyright (c) 2013, Esoteric Software
|
* Copyright (c) 2013, Esoteric Software
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms in whole or in part, with
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* or without modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
* 1. A Spine Single User License or Spine Professional License must be
|
||||||
* list of conditions and the following disclaimer.
|
* purchased from Esoteric Software and the license must remain valid:
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
* http://esotericsoftware.com/
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* 2. Redistributions of source code must retain this license, which is the
|
||||||
* and/or other materials provided with the distribution.
|
* above copyright notice, this declaration of conditions and the following
|
||||||
|
* disclaimer.
|
||||||
|
* 3. Redistributions in binary form must reproduce this license, which is the
|
||||||
|
* above copyright notice, this declaration of conditions and the following
|
||||||
|
* disclaimer, in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
@ -21,7 +29,7 @@
|
|||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
******************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
package com.esotericsoftware.spine;
|
package com.esotericsoftware.spine;
|
||||||
|
|
||||||
@ -215,7 +223,7 @@ public class AnimationState {
|
|||||||
|
|
||||||
public void setTime (float time) {
|
public void setTime (float time) {
|
||||||
currentTime = time;
|
currentTime = time;
|
||||||
currentLastTime = time;
|
currentLastTime = time - 0.00001f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true if no animation is set or if the current time is greater than the animation duration, regardless of looping. */
|
/** Returns true if no animation is set or if the current time is greater than the animation duration, regardless of looping. */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user