mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-05 23:05: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
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* Redistribution and use in source and binary forms in whole or in part, with
|
||||
* or without modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 1. A Spine Single User License or Spine Professional License must be
|
||||
* purchased from Esoteric Software and the license must remain valid:
|
||||
* http://esotericsoftware.com/
|
||||
* 2. Redistributions of source code must retain this license, which is the
|
||||
* 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
|
||||
* 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
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
******************************************************************************/
|
||||
*****************************************************************************/
|
||||
|
||||
package com.esotericsoftware.spine;
|
||||
|
||||
@ -66,8 +74,8 @@ public class Animation {
|
||||
if (skeleton == null) throw new IllegalArgumentException("skeleton cannot be null.");
|
||||
|
||||
if (loop && duration != 0) {
|
||||
lastTime %= duration;
|
||||
time %= duration;
|
||||
lastTime %= duration;
|
||||
}
|
||||
|
||||
Array<Timeline> timelines = this.timelines;
|
||||
@ -539,14 +547,24 @@ public class Animation {
|
||||
int frameCount = frames.length;
|
||||
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;
|
||||
if (frameCount == 1)
|
||||
frameIndex = 0;
|
||||
else {
|
||||
frameIndex = binarySearch(frames, lastTime, 1);
|
||||
float frame = frames[frameIndex];
|
||||
while (frameIndex > 0 && frame == frames[frameIndex - 1])
|
||||
frameIndex--; // Fire multiple events with the same frame.
|
||||
while (frameIndex > 0) {
|
||||
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++)
|
||||
firedEvents.add(events[frameIndex]);
|
||||
|
||||
@ -1,15 +1,23 @@
|
||||
/*******************************************************************************
|
||||
/******************************************************************************
|
||||
* Spine Runtime Software License - Version 1.0
|
||||
*
|
||||
* Copyright (c) 2013, Esoteric Software
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* Redistribution and use in source and binary forms in whole or in part, with
|
||||
* or without modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 1. A Spine Single User License or Spine Professional License must be
|
||||
* purchased from Esoteric Software and the license must remain valid:
|
||||
* http://esotericsoftware.com/
|
||||
* 2. Redistributions of source code must retain this license, which is the
|
||||
* 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
|
||||
* 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
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
******************************************************************************/
|
||||
*****************************************************************************/
|
||||
|
||||
package com.esotericsoftware.spine;
|
||||
|
||||
@ -215,7 +223,7 @@ public class AnimationState {
|
||||
|
||||
public void setTime (float 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. */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user