mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Fixed attachment keys on different tracks.
badlogic/spine-internal#49 (cherry picked from commit 6cccbf61f3bd9f125958fac6eb120b839ae82738)
This commit is contained in:
parent
ac00899175
commit
206e7f983c
@ -531,18 +531,16 @@ public class Animation {
|
|||||||
|
|
||||||
public void apply (Skeleton skeleton, float lastTime, float time, Array<Event> events, float alpha) {
|
public void apply (Skeleton skeleton, float lastTime, float time, Array<Event> events, float alpha) {
|
||||||
float[] frames = this.frames;
|
float[] frames = this.frames;
|
||||||
if (time < frames[0]) {
|
if (time < frames[0]) return; // Time is before first frame.
|
||||||
if (lastTime > time) apply(skeleton, lastTime, Integer.MAX_VALUE, null, 0);
|
|
||||||
return;
|
|
||||||
} else if (lastTime > time) //
|
|
||||||
lastTime = -1;
|
|
||||||
|
|
||||||
int frame = (time >= frames[frames.length - 1] ? frames.length : binarySearch(frames, time)) - 1;
|
int frameIndex;
|
||||||
if (frames[frame] < lastTime) return;
|
if (time >= frames[frames.length - 1]) // Time is after last frame.
|
||||||
|
frameIndex = frames.length - 1;
|
||||||
|
else
|
||||||
|
frameIndex = binarySearch(frames, time, 1) - 1;
|
||||||
|
|
||||||
String attachmentName = attachmentNames[frame];
|
String attachmentName = attachmentNames[frameIndex];
|
||||||
skeleton.slots.get(slotIndex)
|
skeleton.slots.get(slotIndex).attachmentName = attachmentName;
|
||||||
.setAttachment(attachmentName == null ? null : skeleton.getAttachment(slotIndex, attachmentName));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -530,7 +530,7 @@ public class Skeleton {
|
|||||||
for (int i = 0, n = drawOrder.size; i < n; i++) {
|
for (int i = 0, n = drawOrder.size; i < n; i++) {
|
||||||
Slot slot = drawOrder.get(i);
|
Slot slot = drawOrder.get(i);
|
||||||
float[] vertices = null;
|
float[] vertices = null;
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.getAttachment();
|
||||||
if (attachment instanceof RegionAttachment)
|
if (attachment instanceof RegionAttachment)
|
||||||
vertices = ((RegionAttachment)attachment).updateWorldVertices(slot, false);
|
vertices = ((RegionAttachment)attachment).updateWorldVertices(slot, false);
|
||||||
else if (attachment instanceof MeshAttachment) //
|
else if (attachment instanceof MeshAttachment) //
|
||||||
|
|||||||
@ -61,7 +61,7 @@ public class SkeletonBounds {
|
|||||||
|
|
||||||
for (int i = 0; i < slotCount; i++) {
|
for (int i = 0; i < slotCount; i++) {
|
||||||
Slot slot = slots.get(i);
|
Slot slot = slots.get(i);
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.getAttachment();
|
||||||
if (attachment instanceof BoundingBoxAttachment) {
|
if (attachment instanceof BoundingBoxAttachment) {
|
||||||
BoundingBoxAttachment boundingBox = (BoundingBoxAttachment)attachment;
|
BoundingBoxAttachment boundingBox = (BoundingBoxAttachment)attachment;
|
||||||
boundingBoxes.add(boundingBox);
|
boundingBoxes.add(boundingBox);
|
||||||
|
|||||||
@ -52,7 +52,7 @@ public class SkeletonMeshRenderer extends SkeletonRenderer<PolygonSpriteBatch> {
|
|||||||
Array<Slot> drawOrder = skeleton.drawOrder;
|
Array<Slot> drawOrder = skeleton.drawOrder;
|
||||||
for (int i = 0, n = drawOrder.size; i < n; i++) {
|
for (int i = 0, n = drawOrder.size; i < n; i++) {
|
||||||
Slot slot = drawOrder.get(i);
|
Slot slot = drawOrder.get(i);
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.getAttachment();
|
||||||
Texture texture = null;
|
Texture texture = null;
|
||||||
if (attachment instanceof RegionAttachment) {
|
if (attachment instanceof RegionAttachment) {
|
||||||
RegionAttachment region = (RegionAttachment)attachment;
|
RegionAttachment region = (RegionAttachment)attachment;
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public class SkeletonRenderer<T extends Batch> {
|
|||||||
Array<Slot> drawOrder = skeleton.drawOrder;
|
Array<Slot> drawOrder = skeleton.drawOrder;
|
||||||
for (int i = 0, n = drawOrder.size; i < n; i++) {
|
for (int i = 0, n = drawOrder.size; i < n; i++) {
|
||||||
Slot slot = drawOrder.get(i);
|
Slot slot = drawOrder.get(i);
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.getAttachment();
|
||||||
if (attachment instanceof RegionAttachment) {
|
if (attachment instanceof RegionAttachment) {
|
||||||
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
||||||
float[] vertices = regionAttachment.updateWorldVertices(slot, premultipliedAlpha);
|
float[] vertices = regionAttachment.updateWorldVertices(slot, premultipliedAlpha);
|
||||||
|
|||||||
@ -102,7 +102,7 @@ public class SkeletonRendererDebug {
|
|||||||
Array<Slot> slots = skeleton.getSlots();
|
Array<Slot> slots = skeleton.getSlots();
|
||||||
for (int i = 0, n = slots.size; i < n; i++) {
|
for (int i = 0, n = slots.size; i < n; i++) {
|
||||||
Slot slot = slots.get(i);
|
Slot slot = slots.get(i);
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.getAttachment();
|
||||||
if (attachment instanceof RegionAttachment) {
|
if (attachment instanceof RegionAttachment) {
|
||||||
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
RegionAttachment regionAttachment = (RegionAttachment)attachment;
|
||||||
float[] vertices = regionAttachment.updateWorldVertices(slot, false);
|
float[] vertices = regionAttachment.updateWorldVertices(slot, false);
|
||||||
@ -118,7 +118,7 @@ public class SkeletonRendererDebug {
|
|||||||
Array<Slot> slots = skeleton.getSlots();
|
Array<Slot> slots = skeleton.getSlots();
|
||||||
for (int i = 0, n = slots.size; i < n; i++) {
|
for (int i = 0, n = slots.size; i < n; i++) {
|
||||||
Slot slot = slots.get(i);
|
Slot slot = slots.get(i);
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.getAttachment();
|
||||||
if (!(attachment instanceof MeshAttachment)) continue;
|
if (!(attachment instanceof MeshAttachment)) continue;
|
||||||
MeshAttachment mesh = (MeshAttachment)attachment;
|
MeshAttachment mesh = (MeshAttachment)attachment;
|
||||||
mesh.updateWorldVertices(slot, false);
|
mesh.updateWorldVertices(slot, false);
|
||||||
@ -167,7 +167,7 @@ public class SkeletonRendererDebug {
|
|||||||
Array<Slot> slots = skeleton.getSlots();
|
Array<Slot> slots = skeleton.getSlots();
|
||||||
for (int i = 0, n = slots.size; i < n; i++) {
|
for (int i = 0, n = slots.size; i < n; i++) {
|
||||||
Slot slot = slots.get(i);
|
Slot slot = slots.get(i);
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.getAttachment();
|
||||||
if (!(attachment instanceof PathAttachment)) continue;
|
if (!(attachment instanceof PathAttachment)) continue;
|
||||||
PathAttachment path = (PathAttachment)attachment;
|
PathAttachment path = (PathAttachment)attachment;
|
||||||
int nn = path.getWorldVerticesLength();
|
int nn = path.getWorldVerticesLength();
|
||||||
|
|||||||
@ -102,7 +102,7 @@ public class Skin {
|
|||||||
for (Entry<Key, Attachment> entry : oldSkin.attachments.entries()) {
|
for (Entry<Key, Attachment> entry : oldSkin.attachments.entries()) {
|
||||||
int slotIndex = entry.key.slotIndex;
|
int slotIndex = entry.key.slotIndex;
|
||||||
Slot slot = skeleton.slots.get(slotIndex);
|
Slot slot = skeleton.slots.get(slotIndex);
|
||||||
if (slot.attachment == entry.value) {
|
if (slot.getAttachment() == entry.value) {
|
||||||
Attachment attachment = getAttachment(slotIndex, entry.key.name);
|
Attachment attachment = getAttachment(slotIndex, entry.key.name);
|
||||||
if (attachment != null) slot.setAttachment(attachment);
|
if (attachment != null) slot.setAttachment(attachment);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,18 +31,18 @@
|
|||||||
|
|
||||||
package com.esotericsoftware.spine;
|
package com.esotericsoftware.spine;
|
||||||
|
|
||||||
import com.esotericsoftware.spine.attachments.Attachment;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.utils.FloatArray;
|
import com.badlogic.gdx.utils.FloatArray;
|
||||||
|
import com.esotericsoftware.spine.attachments.Attachment;
|
||||||
|
|
||||||
public class Slot {
|
public class Slot {
|
||||||
final SlotData data;
|
final SlotData data;
|
||||||
final Bone bone;
|
final Bone bone;
|
||||||
final Color color;
|
final Color color;
|
||||||
Attachment attachment;
|
private Attachment attachment;
|
||||||
private float attachmentTime;
|
private float attachmentTime;
|
||||||
private FloatArray attachmentVertices = new FloatArray();
|
private FloatArray attachmentVertices = new FloatArray();
|
||||||
|
String attachmentName;
|
||||||
|
|
||||||
public Slot (SlotData data, Bone bone) {
|
public Slot (SlotData data, Bone bone) {
|
||||||
if (data == null) throw new IllegalArgumentException("data cannot be null.");
|
if (data == null) throw new IllegalArgumentException("data cannot be null.");
|
||||||
@ -82,9 +82,19 @@ public class Slot {
|
|||||||
|
|
||||||
/** @return May be null. */
|
/** @return May be null. */
|
||||||
public Attachment getAttachment () {
|
public Attachment getAttachment () {
|
||||||
|
if (attachmentName != null) {
|
||||||
|
setAttachment(bone.skeleton.getAttachment(data.index, attachmentName));
|
||||||
|
attachmentName = null;
|
||||||
|
}
|
||||||
return attachment;
|
return attachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Sets the name of the attachment which will be used to find the attachment in the skin the next time
|
||||||
|
* {@link #getAttachment()} is called. */
|
||||||
|
public void setAttachmentName (String attachmentName) {
|
||||||
|
this.attachmentName = attachmentName;
|
||||||
|
}
|
||||||
|
|
||||||
/** Sets the attachment and if it changed, resets {@link #getAttachmentTime()} and clears {@link #getAttachmentVertices()}.
|
/** Sets the attachment and if it changed, resets {@link #getAttachmentTime()} and clears {@link #getAttachmentVertices()}.
|
||||||
* @param attachment May be null. */
|
* @param attachment May be null. */
|
||||||
public void setAttachment (Attachment attachment) {
|
public void setAttachment (Attachment attachment) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user