diff --git a/spine-as3/spine-as3/src/spine/Skeleton.as b/spine-as3/spine-as3/src/spine/Skeleton.as index 92e1e4fb8..f7714a5f9 100644 --- a/spine-as3/spine-as3/src/spine/Skeleton.as +++ b/spine-as3/spine-as3/src/spine/Skeleton.as @@ -14,6 +14,8 @@ public class Skeleton { public var time:Number; public var flipX:Boolean; public var flipY:Boolean; + public var x:Number = 0; + public var y:Number = 0; public function Skeleton (data:SkeletonData) { if (data == null) diff --git a/spine-as3/spine-as3/src/spine/attachments/RegionAttachment.as b/spine-as3/spine-as3/src/spine/attachments/RegionAttachment.as index f0f663566..7c0109a75 100644 --- a/spine-as3/spine-as3/src/spine/attachments/RegionAttachment.as +++ b/spine-as3/spine-as3/src/spine/attachments/RegionAttachment.as @@ -86,9 +86,9 @@ public dynamic class RegionAttachment extends Attachment { offset[Y4] = localYCos + localX2Sin; } - public function computeVertices (bone:Bone, vertices:Vector.) : void { - var x:Number = bone.worldX; - var y:Number = bone.worldY; + public function computeVertices (x:Number, y:Number, bone:Bone, vertices:Vector.) : void { + x += bone.worldX; + y += bone.worldY; var m00:Number = bone.m00; var m01:Number = bone.m01; var m10:Number = bone.m10; diff --git a/spine-c/include/spine/RegionAttachment.h b/spine-c/include/spine/RegionAttachment.h index 93850b684..cc25b62ce 100644 --- a/spine-c/include/spine/RegionAttachment.h +++ b/spine-c/include/spine/RegionAttachment.h @@ -55,7 +55,7 @@ struct RegionAttachment { RegionAttachment* RegionAttachment_create (const char* name); void RegionAttachment_setUVs (RegionAttachment* self, float u, float v, float u2, float v2, int/*bool*/rotate); void RegionAttachment_updateOffset (RegionAttachment* self); -void RegionAttachment_computeVertices (RegionAttachment* self, Slot* slot, float* vertices); +void RegionAttachment_computeVertices (RegionAttachment* self, float x, float y, Bone* bone, float* vertices); #ifdef __cplusplus } diff --git a/spine-c/include/spine/Skeleton.h b/spine-c/include/spine/Skeleton.h index 76b053ef3..6ea4eb771 100644 --- a/spine-c/include/spine/Skeleton.h +++ b/spine-c/include/spine/Skeleton.h @@ -50,6 +50,7 @@ struct Skeleton { float r, g, b, a; float time; int/*bool*/flipX, flipY; + float x, y; }; Skeleton* Skeleton_create (SkeletonData* data); diff --git a/spine-c/src/spine/RegionAttachment.c b/spine-c/src/spine/RegionAttachment.c index be8bffa1e..7f7570551 100644 --- a/spine-c/src/spine/RegionAttachment.c +++ b/spine-c/src/spine/RegionAttachment.c @@ -90,15 +90,16 @@ void RegionAttachment_updateOffset (RegionAttachment* self) { self->offset[VERTEX_Y4] = localYCos + localX2Sin; } -void RegionAttachment_computeVertices (RegionAttachment* self, Slot* slot, float* vertices) { +void RegionAttachment_computeVertices (RegionAttachment* self, float x, float y, Bone* bone, float* vertices) { float* offset = self->offset; - Bone* bone = slot->bone; - vertices[VERTEX_X1] = offset[VERTEX_X1] * bone->m00 + offset[VERTEX_Y1] * bone->m01 + bone->worldX; - vertices[VERTEX_Y1] = offset[VERTEX_X1] * bone->m10 + offset[VERTEX_Y1] * bone->m11 + bone->worldY; - vertices[VERTEX_X2] = offset[VERTEX_X2] * bone->m00 + offset[VERTEX_Y2] * bone->m01 + bone->worldX; - vertices[VERTEX_Y2] = offset[VERTEX_X2] * bone->m10 + offset[VERTEX_Y2] * bone->m11 + bone->worldY; - vertices[VERTEX_X3] = offset[VERTEX_X3] * bone->m00 + offset[VERTEX_Y3] * bone->m01 + bone->worldX; - vertices[VERTEX_Y3] = offset[VERTEX_X3] * bone->m10 + offset[VERTEX_Y3] * bone->m11 + bone->worldY; - vertices[VERTEX_X4] = offset[VERTEX_X4] * bone->m00 + offset[VERTEX_Y4] * bone->m01 + bone->worldX; - vertices[VERTEX_Y4] = offset[VERTEX_X4] * bone->m10 + offset[VERTEX_Y4] * bone->m11 + bone->worldY; + x += bone->worldX; + y += bone->worldY; + vertices[VERTEX_X1] = offset[VERTEX_X1] * bone->m00 + offset[VERTEX_Y1] * bone->m01 + x; + vertices[VERTEX_Y1] = offset[VERTEX_X1] * bone->m10 + offset[VERTEX_Y1] * bone->m11 + y; + vertices[VERTEX_X2] = offset[VERTEX_X2] * bone->m00 + offset[VERTEX_Y2] * bone->m01 + x; + vertices[VERTEX_Y2] = offset[VERTEX_X2] * bone->m10 + offset[VERTEX_Y2] * bone->m11 + y; + vertices[VERTEX_X3] = offset[VERTEX_X3] * bone->m00 + offset[VERTEX_Y3] * bone->m01 + x; + vertices[VERTEX_Y3] = offset[VERTEX_X3] * bone->m10 + offset[VERTEX_Y3] * bone->m11 + y; + vertices[VERTEX_X4] = offset[VERTEX_X4] * bone->m00 + offset[VERTEX_Y4] * bone->m01 + x; + vertices[VERTEX_Y4] = offset[VERTEX_X4] * bone->m10 + offset[VERTEX_Y4] * bone->m11 + y; } diff --git a/spine-cocos2d-iphone/src/spine/CCSkeleton.m b/spine-cocos2d-iphone/src/spine/CCSkeleton.m index 3b257fc59..331c1d472 100644 --- a/spine-cocos2d-iphone/src/spine/CCSkeleton.m +++ b/spine-cocos2d-iphone/src/spine/CCSkeleton.m @@ -219,7 +219,7 @@ Slot* slot = _skeleton->slots[i]; if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue; RegionAttachment* attachment = (RegionAttachment*)slot->attachment; - RegionAttachment_computeVertices(attachment, slot, vertices); + RegionAttachment_computeVertices(attachment, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices); minX = fmin(minX, vertices[VERTEX_X1] * scaleX); minY = fmin(minY, vertices[VERTEX_Y1] * scaleY); maxX = fmax(maxX, vertices[VERTEX_X1] * scaleX); diff --git a/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.m b/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.m index 60bdf39e7..4a7d42320 100644 --- a/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.m +++ b/spine-cocos2d-iphone/src/spine/spine-cocos2d-iphone.m @@ -48,7 +48,7 @@ char* _Util_readFile (const char* path, int* length) { void RegionAttachment_updateQuad (RegionAttachment* self, Slot* slot, ccV3F_C4B_T2F_Quad* quad, bool premultipliedAlpha) { float vertices[8]; - RegionAttachment_computeVertices(self, slot, vertices); + RegionAttachment_computeVertices(self, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices); GLubyte r = slot->skeleton->r * slot->r * 255; GLubyte g = slot->skeleton->g * slot->g * 255; diff --git a/spine-cocos2dx/src/spine/CCSkeleton.cpp b/spine-cocos2dx/src/spine/CCSkeleton.cpp index 81b416c41..b92a303ab 100644 --- a/spine-cocos2dx/src/spine/CCSkeleton.cpp +++ b/spine-cocos2dx/src/spine/CCSkeleton.cpp @@ -212,7 +212,7 @@ CCRect CCSkeleton::boundingBox () { Slot* slot = skeleton->slots[i]; if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue; RegionAttachment* attachment = (RegionAttachment*)slot->attachment; - RegionAttachment_computeVertices(attachment, slot, vertices); + RegionAttachment_computeVertices(attachment, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices); minX = min(minX, vertices[VERTEX_X1] * scaleX); minY = min(minY, vertices[VERTEX_Y1] * scaleY); maxX = max(maxX, vertices[VERTEX_X1] * scaleX); diff --git a/spine-cocos2dx/src/spine/spine-cocos2dx.cpp b/spine-cocos2dx/src/spine/spine-cocos2dx.cpp index 7337eec5c..df403bf33 100644 --- a/spine-cocos2dx/src/spine/spine-cocos2dx.cpp +++ b/spine-cocos2dx/src/spine/spine-cocos2dx.cpp @@ -53,7 +53,7 @@ char* _Util_readFile (const char* path, int* length) { void RegionAttachment_updateQuad (RegionAttachment* self, Slot* slot, ccV3F_C4B_T2F_Quad* quad, bool premultipliedAlpha) { float vertices[8]; - RegionAttachment_computeVertices(self, slot, vertices); + RegionAttachment_computeVertices(self, slot->skeleton->x, slot->skeleton->y, slot->bone, vertices); GLubyte r = slot->skeleton->r * slot->r * 255; GLubyte g = slot->skeleton->g * slot->g * 255; diff --git a/spine-csharp/src/Attachments/RegionAttachment.cs b/spine-csharp/src/Attachments/RegionAttachment.cs index e01600cfd..b78f0668b 100644 --- a/spine-csharp/src/Attachments/RegionAttachment.cs +++ b/spine-csharp/src/Attachments/RegionAttachment.cs @@ -122,9 +122,9 @@ namespace Spine { offset[Y4] = localYCos + localX2Sin; } - public void ComputeVertices (Bone bone, float[] vertices) { - float x = bone.WorldX; - float y = bone.WorldY; + public void ComputeVertices (float x, float y, Bone bone, float[] vertices) { + x += bone.WorldX; + y += bone.WorldY; float m00 = bone.M00; float m01 = bone.M01; float m10 = bone.M10; diff --git a/spine-csharp/src/Bone.cs b/spine-csharp/src/Bone.cs index 60860ec84..c395665fc 100644 --- a/spine-csharp/src/Bone.cs +++ b/spine-csharp/src/Bone.cs @@ -61,7 +61,6 @@ namespace Spine { if (parent != null) { WorldX = X * parent.M00 + Y * parent.M01 + parent.WorldX; WorldY = X * parent.M10 + Y * parent.M11 + parent.WorldY; - if (Data.InheritScale) { WorldScaleX = parent.WorldScaleX * ScaleX; WorldScaleY = parent.WorldScaleY * ScaleY; @@ -69,13 +68,10 @@ namespace Spine { WorldScaleX = ScaleX; WorldScaleY = ScaleY; } - WorldRotation = Data.InheritRotation ? parent.WorldRotation + Rotation : Rotation; - } else { - - WorldX = X; - WorldY = Y; + WorldX = flipX ? -X : X; + WorldY = flipY ? -Y : Y; WorldScaleX = ScaleX; WorldScaleY = ScaleY; WorldRotation = Rotation; diff --git a/spine-csharp/src/Skeleton.cs b/spine-csharp/src/Skeleton.cs index 8bd69a87c..2d4bb109c 100644 --- a/spine-csharp/src/Skeleton.cs +++ b/spine-csharp/src/Skeleton.cs @@ -45,6 +45,8 @@ namespace Spine { return Bones.Count == 0 ? null : Bones[0]; } } + public float X { get; set; } + public float Y { get; set; } public Skeleton (SkeletonData data) { if (data == null) throw new ArgumentNullException("data cannot be null."); diff --git a/spine-js/spine.js b/spine-js/spine.js index b1f021e5a..3e9788923 100644 --- a/spine-js/spine.js +++ b/spine-js/spine.js @@ -550,6 +550,7 @@ spine.Skeleton = function (skeletonData) { } }; spine.Skeleton.prototype = { + x: 0, y: 0, skin: null, r: 1, g: 1, b: 1, a: 1, time: 0, @@ -725,9 +726,9 @@ spine.RegionAttachment.prototype = { offset[6/*X4*/] = localX2Cos - localYSin; offset[7/*Y4*/] = localYCos + localX2Sin; }, - computeVertices: function (bone, vertices) { - var x = bone.worldX; - var y = bone.worldY; + computeVertices: function (x, y, bone, vertices) { + x += bone.worldX; + y += bone.worldY; var m00 = bone.m00; var m01 = bone.m01; var m10 = bone.m10; diff --git a/spine-js/turbulenz/index.html b/spine-js/turbulenz/index.html index 90c6cfa9c..00dfc0d4f 100644 --- a/spine-js/turbulenz/index.html +++ b/spine-js/turbulenz/index.html @@ -131,7 +131,7 @@ function drawSkeleton (batch, skeleton) { var slot = drawOrder[i]; var attachment = slot.attachment; if (!(attachment instanceof spine.RegionAttachment)) continue; - attachment.computeVertices(slot.bone, vertices); + attachment.computeVertices(skeleton.x, skeleton.y, slot.bone, vertices); batch.add( attachment.rendererObject.page.rendererObject, vertices[0], vertices[1], diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Bone.java b/spine-libgdx/src/com/esotericsoftware/spine/Bone.java index 0eb4ba4e1..1de7346e8 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Bone.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Bone.java @@ -78,8 +78,8 @@ public class Bone { } worldRotation = data.inheritRotation ? parent.worldRotation + rotation : rotation; } else { - worldX = x; - worldY = y; + worldX = flipX ? -x : x; + worldY = flipY ? -y : y; worldScaleX = scaleX; worldScaleY = scaleY; worldRotation = rotation; diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java index a1a2a6c4c..70b73f1f6 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java @@ -39,6 +39,7 @@ public class Skeleton { final Color color; float time; boolean flipX, flipY; + float x, y; public Skeleton (SkeletonData data) { if (data == null) throw new IllegalArgumentException("data cannot be null."); @@ -256,6 +257,22 @@ public class Skeleton { this.flipY = flipY; } + public float getX () { + return x; + } + + public void setX (float x) { + this.x = x; + } + + public float getY () { + return y; + } + + public void setY (float y) { + this.y = y; + } + public float getTime () { return time; } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java b/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java index 08f4c484a..0eee4ddb0 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java @@ -26,6 +26,7 @@ package com.esotericsoftware.spine.attachments; import com.esotericsoftware.spine.Bone; +import com.esotericsoftware.spine.Skeleton; import com.esotericsoftware.spine.Slot; import static com.badlogic.gdx.graphics.g2d.SpriteBatch.*; @@ -130,7 +131,8 @@ public class RegionAttachment extends Attachment { } public void updateVertices (Slot slot) { - Color skeletonColor = slot.getSkeleton().getColor(); + Skeleton skeleton = slot.getSkeleton(); + Color skeletonColor = skeleton.getColor(); Color slotColor = slot.getColor(); float color = NumberUtils.intToFloatColor( // ((int)(255 * skeletonColor.a * slotColor.a) << 24) // @@ -145,8 +147,8 @@ public class RegionAttachment extends Attachment { float[] offset = this.offset; Bone bone = slot.getBone(); - float x = bone.getWorldX(); - float y = bone.getWorldY(); + float x = bone.getWorldX() + skeleton.getX(); + float y = bone.getWorldY() + skeleton.getY(); float m00 = bone.getM00(); float m01 = bone.getM01(); float m10 = bone.getM10(); diff --git a/spine-sfml/src/spine/spine-sfml.cpp b/spine-sfml/src/spine/spine-sfml.cpp index 1758626af..c77838a05 100644 --- a/spine-sfml/src/spine/spine-sfml.cpp +++ b/spine-sfml/src/spine/spine-sfml.cpp @@ -84,7 +84,7 @@ void SkeletonDrawable::draw (RenderTarget& target, RenderStates states) const { Attachment* attachment = slot->attachment; if (!attachment || attachment->type != ATTACHMENT_REGION) continue; RegionAttachment* regionAttachment = (RegionAttachment*)attachment; - RegionAttachment_computeVertices(regionAttachment, slot, vertexPositions); + RegionAttachment_computeVertices(regionAttachment, slot->skeleton->x, slot->skeleton->y, slot->bone, vertexPositions); Uint8 r = skeleton->r * slot->r * 255; Uint8 g = skeleton->g * slot->g * 255; diff --git a/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as b/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as index 47f8dc37e..8a15513fe 100644 --- a/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as +++ b/spine-starling/spine-starling/src/spine/starling/SkeletonSprite.as @@ -41,7 +41,7 @@ public class SkeletonSprite extends DisplayObject implements IAnimatable { var regionAttachment:RegionAttachment = slot.attachment as RegionAttachment; if (regionAttachment != null) { var vertices:Vector. = this.vertices; - regionAttachment.computeVertices(slot.bone, vertices); + regionAttachment.computeVertices(skeleton.x, skeleton.y, slot.bone, vertices); var r:Number = skeleton.r * slot.r; var g:Number = skeleton.g * slot.g; var b:Number = skeleton.b * slot.b; @@ -99,7 +99,7 @@ public class SkeletonSprite extends DisplayObject implements IAnimatable { continue; var vertices:Vector. = this.vertices; - regionAttachment.computeVertices(slot.bone, vertices); + regionAttachment.computeVertices(skeleton.x, skeleton.y, slot.bone, vertices); value = vertices[0]; if (value < minX) diff --git a/spine-tk2d/Code/tk2dSpineSkeleton.cs b/spine-tk2d/Code/tk2dSpineSkeleton.cs index df593c684..4f2fa853a 100644 --- a/spine-tk2d/Code/tk2dSpineSkeleton.cs +++ b/spine-tk2d/Code/tk2dSpineSkeleton.cs @@ -78,7 +78,7 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor if (attachment is RegionAttachment) { RegionAttachment regionAttachment = attachment as RegionAttachment; - regionAttachment.ComputeVertices(slot.Bone,vertexPositions); + regionAttachment.ComputeVertices(skeleton.X, skeleton.Y, slot.Bone, vertexPositions); int vertexIndex = quadIndex * 4; vertices[vertexIndex + 0] = new Vector3(vertexPositions[RegionAttachment.X1],vertexPositions[RegionAttachment.Y1],0); diff --git a/spine-xna/src/SkeletonRenderer.cs b/spine-xna/src/SkeletonRenderer.cs index be7ec4ae6..64f8b6780 100644 --- a/spine-xna/src/SkeletonRenderer.cs +++ b/spine-xna/src/SkeletonRenderer.cs @@ -101,7 +101,7 @@ namespace Spine { item.vertexTR.Color.A = a; float[] vertices = this.vertices; - regionAttachment.ComputeVertices(slot.Bone, vertices); + regionAttachment.ComputeVertices(skeleton.X, skeleton.Y, slot.Bone, vertices); item.vertexTL.Position.X = vertices[RegionAttachment.X1]; item.vertexTL.Position.Y = vertices[RegionAttachment.Y1]; item.vertexTL.Position.Z = 0;