• Editor
  • How to bind one skeleton to a bone in an other skeleton?

For example I have a character with many weapon, and each weapon have two part: left-hand and right-hand.
I create multi project, the character without weapon is one project, and each weapon has a project.

The character has two specify bone which named "left hand" and "right hand"
In each weapon, under the root bone, have two bone named "left hand weapon" and "right hand weapon". The weapon may have it's own animations, need to play separately. For instance a hunter hold a bow, when he play attack animation, the bow need play at the same time.

I want to load the weapon project, and attach the left-hand and right-hand bone under the character project, just like many 3D game skeleton system do.

I look through the API document but no good idea. Is there any way to achieve that?

And I want to request whether to add a feature, that user can load an external spine project into this project, attach it under a slot as an attachment.
It will useful if the character need to change cloth, some cloth has many frame animation to present the wind blow the cloth, but some cloth like armor is just an image. Current the spine support frame animation but in embed into the animation timeline. If I have a walk animation, I need build the frame animation inside the walk animation, so I need the create the animation for each type of cloth.

May be there have some other way to solve this problem elegant, for I am a newbie of spine, I am not quite sure whether I am right.

I am add a SkeletonAttachment as a subclass of Attachment in actionscript code:

package spine.starling
{
    import spine.attachments.Attachment;
    import spine.starling.SkeletonAnimation;
    
public class SkeletonAttachment extends Attachment { private var _skeletion:SkeletonAnimation; public function SkeletonAttachment(name:String, skeletion:SkeletonAnimation) { super(name); _skeletion = skeletion; } public function set skeletion(skeletion:SkeletonAnimation):void { _skeletion = skeletion; } public function get skeletion():SkeletonAnimation { return _skeletion; } } }

And I modify the SkeletonSprite render function:

override public function render (support:RenderSupport, alpha:Number) : void {
		alpha *= this.alpha * skeleton.a;
		var drawOrder:Vector.<Slot> = skeleton.drawOrder;
		for (var i:int = 0, n:int = drawOrder.length; i < n; i++) {
			var slot:Slot = drawOrder[i];
			var regionAttachment:RegionAttachment = slot.attachment as RegionAttachment;
			if (regionAttachment != null) {
				var vertices:Vector.<Number> = this.vertices;
				regionAttachment.computeWorldVertices(skeleton.x, skeleton.y, slot.bone, vertices);
				var r:Number = skeleton.r * slot.r * 255;
				var g:Number = skeleton.g * slot.g * 255;
				var b:Number = skeleton.b * slot.b * 255;
				var a:Number = slot.a;
				var rgb:uint = Color.rgb(r,g,b);

			var image:SkeletonImage = regionAttachment.rendererObject as SkeletonImage;
			var vertexData:Vector.<Number> = image.vertexData.rawData;
					
			image.vertexData.setPosition(0, vertices[2], vertices[3]);				
            image.vertexData.setColor(0, rgb);
            image.vertexData.setAlpha(0, a);
			
			image.vertexData.setPosition(1, vertices[4], vertices[5]);
            image.vertexData.setColor(1, rgb);
            image.vertexData.setAlpha(1, a);
			
			image.vertexData.setPosition(2, vertices[0], vertices[1]);
            image.vertexData.setColor(2, rgb);
            image.vertexData.setAlpha(2, a);
			
			image.vertexData.setPosition(3, vertices[6], vertices[7]);
            image.vertexData.setColor(3, rgb);
            image.vertexData.setAlpha(3, a);

			image.updateVertices();
			support.blendMode = slot.data.additiveBlending ? BlendMode.ADD : BlendMode.NORMAL;
			support.batchQuad(image, alpha, image.texture);
		}
        else
        {
            var skeletonAttachment:SkeletonAttachment = slot.attachment as SkeletonAttachment;
            if (skeletonAttachment != null) {
                var skt:SkeletonAnimation = skeletonAttachment.skeletion;
                
                if (skt.hasVisibleArea)
                {
                    skt.x = slot.bone.worldX;
                    skt.y = slot.bone.worldY;
                    skt.rotation = slot.bone.worldRotation * (3.1415926) / 180;
                    skt.scaleX = slot.bone.worldScaleX;
                    skt.scaleY = slot.bone.worldScaleY;
                    
                    skt.alpha = slot.a;
                    
                    var filter:FragmentFilter = skt.filter;
                    
                    support.pushMatrix();
                    support.transformMatrix(skt);
                    support.blendMode = skt.blendMode;
                    
                    if (filter) filter.render(skt, support, alpha);
                    else        skt.render(support, alpha);
                    
                    support.blendMode = blendMode;
                    support.popMatrix();
                }
            }
        }
	}
}

Hope for response, Thanks!

Related Discussions
...

There are two approaches:

1) Draw the second skeleton on top of the first using the world transform of a bone in the first skeleton. The second skeleton is always on top of the first.
2) Implement an attachment that has the second skeleton and make your skeleton renderer know how to render that attachment. The second skeleton uses the draw order of the slot it is in.

So you have the right idea if you want to implement #2. What doesn't work about your implementation?

I would like to put together an example of doing this but haven't had time. Here is the task:
https://trello.com/c/lCDvU9La/42-cocos2 ... -skeletons

Will I think I am finish the modify for action script runtime, add a new attachment for a skeleton. Can I fork the respo and send a pull request, I hope it could be accepted, do not want to always change my code when the official version is update.

Sure, PRs are always welcome.

2 mois plus tard

Hi,

Just wanted to check to see if there's any plans to officially support skeleton attachments? I'm about to implement a system for cocos2d-x but wanted to make sure first.

Thanks!

It's planned, can't say when it will actually make it in. We already have it on our trello board and Nate did a bit of work on it.

It would be a really useful feature ! Does that mean it will be possible to change on-the-fly the skeleton onto an skeletonAttachment ?