|
@@ -32,7 +32,7 @@ module spine {
|
|
/** Stores the current pose for a skeleton.
|
|
/** Stores the current pose for a skeleton.
|
|
*
|
|
*
|
|
* See [Instance objects](http://esotericsoftware.com/spine-runtime-architecture#Instance-objects) in the Spine Runtimes Guide. */
|
|
* See [Instance objects](http://esotericsoftware.com/spine-runtime-architecture#Instance-objects) in the Spine Runtimes Guide. */
|
|
- export class Skeleton {
|
|
|
|
|
|
+ export class Skeleton {
|
|
/** The skeleton's setup pose data. */
|
|
/** The skeleton's setup pose data. */
|
|
data: SkeletonData;
|
|
data: SkeletonData;
|
|
|
|
|
|
@@ -69,11 +69,11 @@ module spine {
|
|
time = 0;
|
|
time = 0;
|
|
|
|
|
|
/** Scales the entire skeleton on the X axis. This affects all bones, even if the bone's transform mode disallows scale
|
|
/** Scales the entire skeleton on the X axis. This affects all bones, even if the bone's transform mode disallows scale
|
|
- * inheritance. */
|
|
|
|
|
|
+ * inheritance. */
|
|
scaleX = 1;
|
|
scaleX = 1;
|
|
|
|
|
|
/** Scales the entire skeleton on the Y axis. This affects all bones, even if the bone's transform mode disallows scale
|
|
/** Scales the entire skeleton on the Y axis. This affects all bones, even if the bone's transform mode disallows scale
|
|
- * inheritance. */
|
|
|
|
|
|
+ * inheritance. */
|
|
scaleY = 1;
|
|
scaleY = 1;
|
|
|
|
|
|
/** Sets the skeleton X position, which is added to the root bone worldX position. */
|
|
/** Sets the skeleton X position, which is added to the root bone worldX position. */
|
|
@@ -82,7 +82,7 @@ module spine {
|
|
/** Sets the skeleton Y position, which is added to the root bone worldY position. */
|
|
/** Sets the skeleton Y position, which is added to the root bone worldY position. */
|
|
y = 0;
|
|
y = 0;
|
|
|
|
|
|
- constructor(data: SkeletonData) {
|
|
|
|
|
|
+ constructor (data: SkeletonData) {
|
|
if (!data) throw new Error("data cannot be null.");
|
|
if (!data) throw new Error("data cannot be null.");
|
|
this.data = data;
|
|
this.data = data;
|
|
|
|
|
|
@@ -134,7 +134,7 @@ module spine {
|
|
|
|
|
|
/** Caches information about bones and constraints. Must be called if the {@link #getSkin()} is modified or if bones,
|
|
/** Caches information about bones and constraints. Must be called if the {@link #getSkin()} is modified or if bones,
|
|
* constraints, or weighted path attachments are added or removed. */
|
|
* constraints, or weighted path attachments are added or removed. */
|
|
- updateCache() {
|
|
|
|
|
|
+ updateCache () {
|
|
let updateCache = this._updateCache;
|
|
let updateCache = this._updateCache;
|
|
updateCache.length = 0;
|
|
updateCache.length = 0;
|
|
|
|
|
|
@@ -193,7 +193,7 @@ module spine {
|
|
this.sortBone(bones[i]);
|
|
this.sortBone(bones[i]);
|
|
}
|
|
}
|
|
|
|
|
|
- sortIkConstraint(constraint: IkConstraint) {
|
|
|
|
|
|
+ sortIkConstraint (constraint: IkConstraint) {
|
|
constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin && Utils.contains(this.skin.constraints, constraint.data, true)));
|
|
constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin && Utils.contains(this.skin.constraints, constraint.data, true)));
|
|
if (!constraint.active) return;
|
|
if (!constraint.active) return;
|
|
|
|
|
|
@@ -218,7 +218,7 @@ module spine {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- sortPathConstraint(constraint: PathConstraint) {
|
|
|
|
|
|
+ sortPathConstraint (constraint: PathConstraint) {
|
|
constraint.active = constraint.target.bone.isActive() && (!constraint.data.skinRequired || (this.skin && Utils.contains(this.skin.constraints, constraint.data, true)));
|
|
constraint.active = constraint.target.bone.isActive() && (!constraint.data.skinRequired || (this.skin && Utils.contains(this.skin.constraints, constraint.data, true)));
|
|
if (!constraint.active) return;
|
|
if (!constraint.active) return;
|
|
|
|
|
|
@@ -247,7 +247,7 @@ module spine {
|
|
constrained[i].sorted = true;
|
|
constrained[i].sorted = true;
|
|
}
|
|
}
|
|
|
|
|
|
- sortTransformConstraint(constraint: TransformConstraint) {
|
|
|
|
|
|
+ sortTransformConstraint (constraint: TransformConstraint) {
|
|
constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin && Utils.contains(this.skin.constraints, constraint.data, true)));
|
|
constraint.active = constraint.target.isActive() && (!constraint.data.skinRequired || (this.skin && Utils.contains(this.skin.constraints, constraint.data, true)));
|
|
if (!constraint.active) return;
|
|
if (!constraint.active) return;
|
|
|
|
|
|
@@ -275,7 +275,7 @@ module spine {
|
|
constrained[i].sorted = true;
|
|
constrained[i].sorted = true;
|
|
}
|
|
}
|
|
|
|
|
|
- sortPathConstraintAttachment(skin: Skin, slotIndex: number, slotBone: Bone) {
|
|
|
|
|
|
+ sortPathConstraintAttachment (skin: Skin, slotIndex: number, slotBone: Bone) {
|
|
let attachments = skin.attachments[slotIndex];
|
|
let attachments = skin.attachments[slotIndex];
|
|
if (!attachments) return;
|
|
if (!attachments) return;
|
|
for (let key in attachments) {
|
|
for (let key in attachments) {
|
|
@@ -283,7 +283,7 @@ module spine {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- sortPathConstraintAttachmentWith(attachment: Attachment, slotBone: Bone) {
|
|
|
|
|
|
+ sortPathConstraintAttachmentWith (attachment: Attachment, slotBone: Bone) {
|
|
if (!(attachment instanceof PathAttachment)) return;
|
|
if (!(attachment instanceof PathAttachment)) return;
|
|
let pathBones = (<PathAttachment>attachment).bones;
|
|
let pathBones = (<PathAttachment>attachment).bones;
|
|
if (!pathBones)
|
|
if (!pathBones)
|
|
@@ -299,7 +299,7 @@ module spine {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- sortBone(bone: Bone) {
|
|
|
|
|
|
+ sortBone (bone: Bone) {
|
|
if (bone.sorted) return;
|
|
if (bone.sorted) return;
|
|
let parent = bone.parent;
|
|
let parent = bone.parent;
|
|
if (parent) this.sortBone(parent);
|
|
if (parent) this.sortBone(parent);
|
|
@@ -307,7 +307,7 @@ module spine {
|
|
this._updateCache.push(bone);
|
|
this._updateCache.push(bone);
|
|
}
|
|
}
|
|
|
|
|
|
- sortReset(bones: Array<Bone>) {
|
|
|
|
|
|
+ sortReset (bones: Array<Bone>) {
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
let bone = bones[i];
|
|
let bone = bones[i];
|
|
if (!bone.active) continue;
|
|
if (!bone.active) continue;
|
|
@@ -320,7 +320,7 @@ module spine {
|
|
*
|
|
*
|
|
* See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
|
|
* See [World transforms](http://esotericsoftware.com/spine-runtime-skeletons#World-transforms) in the Spine
|
|
* Runtimes Guide. */
|
|
* Runtimes Guide. */
|
|
- updateWorldTransform() {
|
|
|
|
|
|
+ updateWorldTransform () {
|
|
let bones = this.bones;
|
|
let bones = this.bones;
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
let bone = bones[i];
|
|
let bone = bones[i];
|
|
@@ -338,7 +338,7 @@ module spine {
|
|
updateCache[i].update();
|
|
updateCache[i].update();
|
|
}
|
|
}
|
|
|
|
|
|
- updateWorldTransformWith(parent: Bone) {
|
|
|
|
|
|
+ updateWorldTransformWith (parent: Bone) {
|
|
// Apply the parent bone transform to the root bone. The root bone always inherits scale, rotation and reflection.
|
|
// Apply the parent bone transform to the root bone. The root bone always inherits scale, rotation and reflection.
|
|
let rootBone = this.getRootBone();
|
|
let rootBone = this.getRootBone();
|
|
let pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
|
|
let pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d;
|
|
@@ -364,13 +364,13 @@ module spine {
|
|
}
|
|
}
|
|
|
|
|
|
/** Sets the bones, constraints, and slots to their setup pose values. */
|
|
/** Sets the bones, constraints, and slots to their setup pose values. */
|
|
- setToSetupPose() {
|
|
|
|
|
|
+ setToSetupPose () {
|
|
this.setBonesToSetupPose();
|
|
this.setBonesToSetupPose();
|
|
this.setSlotsToSetupPose();
|
|
this.setSlotsToSetupPose();
|
|
}
|
|
}
|
|
|
|
|
|
/** Sets the bones and constraints to their setup pose values. */
|
|
/** Sets the bones and constraints to their setup pose values. */
|
|
- setBonesToSetupPose() {
|
|
|
|
|
|
+ setBonesToSetupPose () {
|
|
let bones = this.bones;
|
|
let bones = this.bones;
|
|
for (let i = 0, n = bones.length; i < n; i++)
|
|
for (let i = 0, n = bones.length; i < n; i++)
|
|
bones[i].setToSetupPose();
|
|
bones[i].setToSetupPose();
|
|
@@ -410,7 +410,7 @@ module spine {
|
|
}
|
|
}
|
|
|
|
|
|
/** Sets the slots and draw order to their setup pose values. */
|
|
/** Sets the slots and draw order to their setup pose values. */
|
|
- setSlotsToSetupPose() {
|
|
|
|
|
|
+ setSlotsToSetupPose () {
|
|
let slots = this.slots;
|
|
let slots = this.slots;
|
|
Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length);
|
|
Utils.arrayCopy(slots, 0, this.drawOrder, 0, slots.length);
|
|
for (let i = 0, n = slots.length; i < n; i++)
|
|
for (let i = 0, n = slots.length; i < n; i++)
|
|
@@ -418,13 +418,13 @@ module spine {
|
|
}
|
|
}
|
|
|
|
|
|
/** @returns May return null. */
|
|
/** @returns May return null. */
|
|
- getRootBone() {
|
|
|
|
|
|
+ getRootBone () {
|
|
if (this.bones.length == 0) return null;
|
|
if (this.bones.length == 0) return null;
|
|
return this.bones[0];
|
|
return this.bones[0];
|
|
}
|
|
}
|
|
|
|
|
|
/** @returns May be null. */
|
|
/** @returns May be null. */
|
|
- findBone(boneName: string) {
|
|
|
|
|
|
+ findBone (boneName: string) {
|
|
if (!boneName) throw new Error("boneName cannot be null.");
|
|
if (!boneName) throw new Error("boneName cannot be null.");
|
|
let bones = this.bones;
|
|
let bones = this.bones;
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
for (let i = 0, n = bones.length; i < n; i++) {
|
|
@@ -435,7 +435,7 @@ module spine {
|
|
}
|
|
}
|
|
|
|
|
|
/** @returns -1 if the bone was not found. */
|
|
/** @returns -1 if the bone was not found. */
|
|
- findBoneIndex(boneName: string) {
|
|
|
|
|
|
+ findBoneIndex (boneName: string) {
|
|
if (!boneName) throw new Error("boneName cannot be null.");
|
|
if (!boneName) throw new Error("boneName cannot be null.");
|
|
let bones = this.bones;
|
|
let bones = this.bones;
|
|
for (let i = 0, n = bones.length; i < n; i++)
|
|
for (let i = 0, n = bones.length; i < n; i++)
|
|
@@ -446,7 +446,7 @@ module spine {
|
|
/** Finds a slot by comparing each slot's name. It is more efficient to cache the results of this method than to call it
|
|
/** Finds a slot by comparing each slot's name. It is more efficient to cache the results of this method than to call it
|
|
* repeatedly.
|
|
* repeatedly.
|
|
* @returns May be null. */
|
|
* @returns May be null. */
|
|
- findSlot(slotName: string) {
|
|
|
|
|
|
+ findSlot (slotName: string) {
|
|
if (!slotName) throw new Error("slotName cannot be null.");
|
|
if (!slotName) throw new Error("slotName cannot be null.");
|
|
let slots = this.slots;
|
|
let slots = this.slots;
|
|
for (let i = 0, n = slots.length; i < n; i++) {
|
|
for (let i = 0, n = slots.length; i < n; i++) {
|
|
@@ -457,7 +457,7 @@ module spine {
|
|
}
|
|
}
|
|
|
|
|
|
/** @returns -1 if the bone was not found. */
|
|
/** @returns -1 if the bone was not found. */
|
|
- findSlotIndex(slotName: string) {
|
|
|
|
|
|
+ findSlotIndex (slotName: string) {
|
|
if (!slotName) throw new Error("slotName cannot be null.");
|
|
if (!slotName) throw new Error("slotName cannot be null.");
|
|
let slots = this.slots;
|
|
let slots = this.slots;
|
|
for (let i = 0, n = slots.length; i < n; i++)
|
|
for (let i = 0, n = slots.length; i < n; i++)
|
|
@@ -468,7 +468,7 @@ module spine {
|
|
/** Sets a skin by name.
|
|
/** Sets a skin by name.
|
|
*
|
|
*
|
|
* See {@link #setSkin()}. */
|
|
* See {@link #setSkin()}. */
|
|
- setSkinByName(skinName: string) {
|
|
|
|
|
|
+ setSkinByName (skinName: string) {
|
|
let skin = this.data.findSkin(skinName);
|
|
let skin = this.data.findSkin(skinName);
|
|
if (!skin) throw new Error("Skin not found: " + skinName);
|
|
if (!skin) throw new Error("Skin not found: " + skinName);
|
|
this.setSkin(skin);
|
|
this.setSkin(skin);
|
|
@@ -484,7 +484,7 @@ module spine {
|
|
* {@link #setSlotsToSetupPose()}. Also, often {@link AnimationState#apply()} is called before the next time the
|
|
* {@link #setSlotsToSetupPose()}. Also, often {@link AnimationState#apply()} is called before the next time the
|
|
* skeleton is rendered to allow any attachment keys in the current animation(s) to hide or show attachments from the new skin.
|
|
* skeleton is rendered to allow any attachment keys in the current animation(s) to hide or show attachments from the new skin.
|
|
* @param newSkin May be null. */
|
|
* @param newSkin May be null. */
|
|
- setSkin(newSkin: Skin) {
|
|
|
|
|
|
+ setSkin (newSkin: Skin) {
|
|
if (newSkin == this.skin) return;
|
|
if (newSkin == this.skin) return;
|
|
if (newSkin) {
|
|
if (newSkin) {
|
|
if (this.skin)
|
|
if (this.skin)
|
|
@@ -511,7 +511,7 @@ module spine {
|
|
*
|
|
*
|
|
* See {@link #getAttachment()}.
|
|
* See {@link #getAttachment()}.
|
|
* @returns May be null. */
|
|
* @returns May be null. */
|
|
- getAttachmentByName(slotName: string, attachmentName: string): Attachment {
|
|
|
|
|
|
+ getAttachmentByName (slotName: string, attachmentName: string): Attachment {
|
|
return this.getAttachment(this.data.findSlotIndex(slotName), attachmentName);
|
|
return this.getAttachment(this.data.findSlotIndex(slotName), attachmentName);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -520,7 +520,7 @@ module spine {
|
|
*
|
|
*
|
|
* See [Runtime skins](http://esotericsoftware.com/spine-runtime-skins) in the Spine Runtimes Guide.
|
|
* See [Runtime skins](http://esotericsoftware.com/spine-runtime-skins) in the Spine Runtimes Guide.
|
|
* @returns May be null. */
|
|
* @returns May be null. */
|
|
- getAttachment(slotIndex: number, attachmentName: string): Attachment {
|
|
|
|
|
|
+ getAttachment (slotIndex: number, attachmentName: string): Attachment {
|
|
if (!attachmentName) throw new Error("attachmentName cannot be null.");
|
|
if (!attachmentName) throw new Error("attachmentName cannot be null.");
|
|
if (this.skin) {
|
|
if (this.skin) {
|
|
let attachment: Attachment = this.skin.getAttachment(slotIndex, attachmentName);
|
|
let attachment: Attachment = this.skin.getAttachment(slotIndex, attachmentName);
|
|
@@ -533,7 +533,7 @@ module spine {
|
|
/** A convenience method to set an attachment by finding the slot with {@link #findSlot()}, finding the attachment with
|
|
/** A convenience method to set an attachment by finding the slot with {@link #findSlot()}, finding the attachment with
|
|
* {@link #getAttachment()}, then setting the slot's {@link Slot#attachment}.
|
|
* {@link #getAttachment()}, then setting the slot's {@link Slot#attachment}.
|
|
* @param attachmentName May be null to clear the slot's attachment. */
|
|
* @param attachmentName May be null to clear the slot's attachment. */
|
|
- setAttachment(slotName: string, attachmentName: string) {
|
|
|
|
|
|
+ setAttachment (slotName: string, attachmentName: string) {
|
|
if (!slotName) throw new Error("slotName cannot be null.");
|
|
if (!slotName) throw new Error("slotName cannot be null.");
|
|
let slots = this.slots;
|
|
let slots = this.slots;
|
|
for (let i = 0, n = slots.length; i < n; i++) {
|
|
for (let i = 0, n = slots.length; i < n; i++) {
|
|
@@ -555,7 +555,7 @@ module spine {
|
|
/** Finds an IK constraint by comparing each IK constraint's name. It is more efficient to cache the results of this method
|
|
/** Finds an IK constraint by comparing each IK constraint's name. It is more efficient to cache the results of this method
|
|
* than to call it repeatedly.
|
|
* than to call it repeatedly.
|
|
* @return May be null. */
|
|
* @return May be null. */
|
|
- findIkConstraint(constraintName: string) {
|
|
|
|
|
|
+ findIkConstraint (constraintName: string) {
|
|
if (!constraintName) throw new Error("constraintName cannot be null.");
|
|
if (!constraintName) throw new Error("constraintName cannot be null.");
|
|
let ikConstraints = this.ikConstraints;
|
|
let ikConstraints = this.ikConstraints;
|
|
for (let i = 0, n = ikConstraints.length; i < n; i++) {
|
|
for (let i = 0, n = ikConstraints.length; i < n; i++) {
|
|
@@ -568,7 +568,7 @@ module spine {
|
|
/** Finds a transform constraint by comparing each transform constraint's name. It is more efficient to cache the results of
|
|
/** Finds a transform constraint by comparing each transform constraint's name. It is more efficient to cache the results of
|
|
* this method than to call it repeatedly.
|
|
* this method than to call it repeatedly.
|
|
* @return May be null. */
|
|
* @return May be null. */
|
|
- findTransformConstraint(constraintName: string) {
|
|
|
|
|
|
+ findTransformConstraint (constraintName: string) {
|
|
if (!constraintName) throw new Error("constraintName cannot be null.");
|
|
if (!constraintName) throw new Error("constraintName cannot be null.");
|
|
let transformConstraints = this.transformConstraints;
|
|
let transformConstraints = this.transformConstraints;
|
|
for (let i = 0, n = transformConstraints.length; i < n; i++) {
|
|
for (let i = 0, n = transformConstraints.length; i < n; i++) {
|
|
@@ -581,7 +581,7 @@ module spine {
|
|
/** Finds a path constraint by comparing each path constraint's name. It is more efficient to cache the results of this method
|
|
/** Finds a path constraint by comparing each path constraint's name. It is more efficient to cache the results of this method
|
|
* than to call it repeatedly.
|
|
* than to call it repeatedly.
|
|
* @return May be null. */
|
|
* @return May be null. */
|
|
- findPathConstraint(constraintName: string) {
|
|
|
|
|
|
+ findPathConstraint (constraintName: string) {
|
|
if (!constraintName) throw new Error("constraintName cannot be null.");
|
|
if (!constraintName) throw new Error("constraintName cannot be null.");
|
|
let pathConstraints = this.pathConstraints;
|
|
let pathConstraints = this.pathConstraints;
|
|
for (let i = 0, n = pathConstraints.length; i < n; i++) {
|
|
for (let i = 0, n = pathConstraints.length; i < n; i++) {
|
|
@@ -595,7 +595,7 @@ module spine {
|
|
* @param offset An output value, the distance from the skeleton origin to the bottom left corner of the AABB.
|
|
* @param offset An output value, the distance from the skeleton origin to the bottom left corner of the AABB.
|
|
* @param size An output value, the width and height of the AABB.
|
|
* @param size An output value, the width and height of the AABB.
|
|
* @param temp Working memory to temporarily store attachments' computed world vertices. */
|
|
* @param temp Working memory to temporarily store attachments' computed world vertices. */
|
|
- getBounds(offset: Vector2, size: Vector2, temp: Array<number> = new Array<number>(2)) {
|
|
|
|
|
|
+ getBounds (offset: Vector2, size: Vector2, temp: Array<number> = new Array<number>(2)) {
|
|
if (!offset) throw new Error("offset cannot be null.");
|
|
if (!offset) throw new Error("offset cannot be null.");
|
|
if (!size) throw new Error("size cannot be null.");
|
|
if (!size) throw new Error("size cannot be null.");
|
|
let drawOrder = this.drawOrder;
|
|
let drawOrder = this.drawOrder;
|
|
@@ -631,7 +631,7 @@ module spine {
|
|
}
|
|
}
|
|
|
|
|
|
/** Increments the skeleton's {@link #time}. */
|
|
/** Increments the skeleton's {@link #time}. */
|
|
- update(delta: number) {
|
|
|
|
|
|
+ update (delta: number) {
|
|
this.time += delta;
|
|
this.time += delta;
|
|
}
|
|
}
|
|
}
|
|
}
|