Fixed Skeleton copy constructor.

It wasn't copying each bone's children.
This commit is contained in:
NathanSweet 2016-08-14 08:09:58 +02:00
parent 5a7cbf0a41
commit 3160077207
2 changed files with 10 additions and 12 deletions

View File

@ -31,8 +31,6 @@
package com.esotericsoftware.spine; package com.esotericsoftware.spine;
import java.util.Comparator;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
@ -51,7 +49,6 @@ public class Skeleton {
final Array<IkConstraint> ikConstraints; final Array<IkConstraint> ikConstraints;
final Array<TransformConstraint> transformConstraints; final Array<TransformConstraint> transformConstraints;
final Array<PathConstraint> pathConstraints; final Array<PathConstraint> pathConstraints;
final Array<Constraint> sortedConstraints = new Array();
final Array<Updatable> updateCache = new Array(); final Array<Updatable> updateCache = new Array();
final Array<Bone> updateCacheReset = new Array(); final Array<Bone> updateCacheReset = new Array();
Skin skin; Skin skin;
@ -60,12 +57,6 @@ public class Skeleton {
boolean flipX, flipY; boolean flipX, flipY;
float x, y; float x, y;
final Comparator<Constraint> constraintComparator = new Comparator<Constraint>() {
public int compare (Constraint o1, Constraint o2) {
return o1.getOrder() - o2.getOrder();
}
};
public Skeleton (SkeletonData data) { public Skeleton (SkeletonData data) {
if (data == null) throw new IllegalArgumentException("data cannot be null."); if (data == null) throw new IllegalArgumentException("data cannot be null.");
this.data = data; this.data = data;
@ -116,8 +107,15 @@ public class Skeleton {
bones = new Array(skeleton.bones.size); bones = new Array(skeleton.bones.size);
for (Bone bone : skeleton.bones) { for (Bone bone : skeleton.bones) {
Bone parent = bone.parent == null ? null : bones.get(bone.parent.data.index); Bone newBone;
bones.add(new Bone(bone, this, parent)); if (bone.parent == null)
newBone = new Bone(bone, this, null);
else {
Bone parent = bones.get(bone.parent.data.index);
newBone = new Bone(bone, this, parent);
parent.children.add(newBone);
}
bones.add(newBone);
} }
slots = new Array(skeleton.slots.size); slots = new Array(skeleton.slots.size);

View File

@ -168,7 +168,7 @@ public class SkeletonViewer extends ApplicationAdapter {
skeleton = new Skeleton(skeletonData); skeleton = new Skeleton(skeletonData);
skeleton.setToSetupPose(); skeleton.setToSetupPose();
skeleton = new Skeleton(skeleton); skeleton = new Skeleton(skeleton); // Tests copy constructors.
skeleton.updateWorldTransform(); skeleton.updateWorldTransform();
state = new AnimationState(new AnimationStateData(skeletonData)); state = new AnimationState(new AnimationStateData(skeletonData));