I have ported the libgdx runtime from github to as3 and I am having trouble getting the image attachement to line up correctly with the bones.
I believe my issue is in either of two places. In the Bone.as class I changed the updateWorldTransform to use the as3 Matrix class so that it can handle the calculations, here is the method:
public function updateWorldTransform(flipX : Boolean, flipY : Boolean) : void {
var parent : Bone = this._parent;
var scaleX : Number = this.scaleX;
var scaleY : Number = this.scaleY;
if (flipX) {
scaleX = -this.scaleX;
}
if (flipY) {
scaleY = -this.scaleY;
}
_worldTransform.identity();
_worldTransform.translate(this.x, this.y);
_worldTransform.rotate(MathUtils.getRadiansFromDegrees(this.rotation));
_worldTransform.scale(this.scaleX, this.scaleY);
_worldRotation = this.rotation;
if (parent != null) {
var parentTransform : Matrix = parent.worldTransform;
parentTransform.concat(_worldTransform);
_worldRotation += parent.worldRotation;
_worldTransform = parentTransform;
}
}
And in my custom StarlingRegionAttachment.as class that extends from RegionAttachment.as I am trying to draw the image texture in the correct position. Starling has an image class that can have xy coordinates set or you can use a transform matrix. I elected to go with the matrix:
override public function draw (displayObject : *, slot : Slot) : void {
if (_region == null) throw new Error("RegionAttachment is not setup: " + this);
if (_texture == null) throw new Error("RegionAttachment is not setup: " + this);
var batch : QuadBatch = displayObject as QuadBatch;
if(!_image)
_image = new Image(_texture);
var centerX : Number = width / 2;
var centerY : Number = height / 2;
//Get clone of bone world transform
var boneTransform : Matrix = slot.bone.worldTransform;
var imageMatrix : Matrix = _image.transformationMatrix;
imageMatrix.identity();
imageMatrix.translate(this.x - slot.bone.x, this.y - slot.bone.y);
imageMatrix.rotate(MathUtils.getRadiansFromDegrees(this.rotation));
imageMatrix.scale(this.scaleX, this.scaleY);
//imageMatrix.translate(-centerX * this.scaleX, -centerY * this.scaleY);
boneTransform.concat( imageMatrix );
_image.width = this.width;
_image.height = this.height;
_image.transformationMatrix = boneTransform;
batch.addImage(_image);
}
I am not sure if you have any experience with the flash coordinate system and can shed some light on what I may be doing wrong here in my approach. The skin lines up almost right but its still off. If you don't have time, no worries.