mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-05 18:26:52 +08:00
spine-as3, more efficient Flash rendering.
This commit is contained in:
parent
c4d2937b6a
commit
eecb22064e
Binary file not shown.
@ -80,64 +80,68 @@ public class SkeletonSprite extends Sprite {
|
|||||||
for (var i:int = 0, n:int = drawOrder.length; i < n; i++) {
|
for (var i:int = 0, n:int = drawOrder.length; i < n; i++) {
|
||||||
var slot:Slot = drawOrder[i];
|
var slot:Slot = drawOrder[i];
|
||||||
var regionAttachment:RegionAttachment = slot.attachment as RegionAttachment;
|
var regionAttachment:RegionAttachment = slot.attachment as RegionAttachment;
|
||||||
if (regionAttachment) {
|
if (!regionAttachment) continue;
|
||||||
var wrapper:Sprite = wrappers[regionAttachment];
|
|
||||||
|
var wrapper:Sprite = wrappers[regionAttachment];
|
||||||
|
if (!wrapper) {
|
||||||
var region:AtlasRegion = AtlasRegion(regionAttachment.rendererObject);
|
var region:AtlasRegion = AtlasRegion(regionAttachment.rendererObject);
|
||||||
if (!wrapper) {
|
var regionHeight:Number = region.rotate ? region.width : region.height;
|
||||||
|
var regionData:BitmapData = region.rendererObject as BitmapData;
|
||||||
|
if (!regionData) {
|
||||||
var bitmapData:BitmapData = region.page.rendererObject as BitmapData;
|
var bitmapData:BitmapData = region.page.rendererObject as BitmapData;
|
||||||
var regionWidth:Number = region.rotate ? region.height : region.width;
|
var regionWidth:Number = region.rotate ? region.height : region.width;
|
||||||
var regionHeight:Number = region.rotate ? region.width : region.height;
|
regionData = new BitmapData(regionWidth, regionHeight);
|
||||||
var regionData:BitmapData = new BitmapData(regionWidth, regionHeight);
|
|
||||||
regionData.copyPixels(bitmapData, new Rectangle(region.x, region.y, regionWidth, regionHeight), new Point());
|
regionData.copyPixels(bitmapData, new Rectangle(region.x, region.y, regionWidth, regionHeight), new Point());
|
||||||
|
region.rendererObject = regionData;
|
||||||
var bitmap:Bitmap = new Bitmap(regionData);
|
|
||||||
bitmap.smoothing = true;
|
|
||||||
|
|
||||||
// Rotate and scale using default registration point (top left corner, y-down, CW) instead of image center.
|
|
||||||
bitmap.rotation = -regionAttachment.rotation;
|
|
||||||
bitmap.scaleX = regionAttachment.scaleX * (regionAttachment.width / region.width);
|
|
||||||
bitmap.scaleY = regionAttachment.scaleY * (regionAttachment.height / region.height);
|
|
||||||
|
|
||||||
// Position using attachment translation, shifted as if scale and rotation were at image center.
|
|
||||||
var radians:Number = -regionAttachment.rotation * Math.PI / 180;
|
|
||||||
var cos:Number = Math.cos(radians);
|
|
||||||
var sin:Number = Math.sin(radians);
|
|
||||||
var shiftX:Number = -regionAttachment.width / 2 * regionAttachment.scaleX;
|
|
||||||
var shiftY:Number = -regionAttachment.height / 2 * regionAttachment.scaleY;
|
|
||||||
if (region.rotate) {
|
|
||||||
bitmap.rotation += 90;
|
|
||||||
shiftX += regionHeight * (regionAttachment.width / region.width);
|
|
||||||
}
|
|
||||||
bitmap.x = regionAttachment.x + shiftX * cos - shiftY * sin;
|
|
||||||
bitmap.y = -regionAttachment.y + shiftX * sin + shiftY * cos;
|
|
||||||
|
|
||||||
// Use bone as registration point.
|
|
||||||
wrapper = new Sprite();
|
|
||||||
wrapper.transform.colorTransform = new ColorTransform();
|
|
||||||
wrapper.addChild(bitmap);
|
|
||||||
wrappers[regionAttachment] = wrapper;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper.blendMode = blendModes[slot.data.blendMode.ordinal];
|
var bitmap:Bitmap = new Bitmap(regionData);
|
||||||
|
bitmap.smoothing = true;
|
||||||
|
|
||||||
var colorTransform:ColorTransform = wrapper.transform.colorTransform;
|
// Rotate and scale using default registration point (top left corner, y-down, CW) instead of image center.
|
||||||
colorTransform.redMultiplier = skeleton.r * slot.r * regionAttachment.r;
|
bitmap.rotation = -regionAttachment.rotation;
|
||||||
colorTransform.greenMultiplier = skeleton.g * slot.g * regionAttachment.g;
|
bitmap.scaleX = regionAttachment.scaleX * (regionAttachment.width / region.width);
|
||||||
colorTransform.blueMultiplier = skeleton.b * slot.b * regionAttachment.b;
|
bitmap.scaleY = regionAttachment.scaleY * (regionAttachment.height / region.height);
|
||||||
colorTransform.alphaMultiplier = skeleton.a * slot.a * regionAttachment.a;
|
|
||||||
wrapper.transform.colorTransform = colorTransform;
|
|
||||||
|
|
||||||
var bone:Bone = slot.bone;
|
// Position using attachment translation, shifted as if scale and rotation were at image center.
|
||||||
var flipX:int = skeleton.flipX ? -1 : 1;
|
var radians:Number = -regionAttachment.rotation * Math.PI / 180;
|
||||||
var flipY:int = skeleton.flipY ? -1 : 1;
|
var cos:Number = Math.cos(radians);
|
||||||
|
var sin:Number = Math.sin(radians);
|
||||||
|
var shiftX:Number = -regionAttachment.width / 2 * regionAttachment.scaleX;
|
||||||
|
var shiftY:Number = -regionAttachment.height / 2 * regionAttachment.scaleY;
|
||||||
|
if (region.rotate) {
|
||||||
|
bitmap.rotation += 90;
|
||||||
|
shiftX += regionHeight * (regionAttachment.width / region.width);
|
||||||
|
}
|
||||||
|
bitmap.x = regionAttachment.x + shiftX * cos - shiftY * sin;
|
||||||
|
bitmap.y = -regionAttachment.y + shiftX * sin + shiftY * cos;
|
||||||
|
|
||||||
wrapper.x = bone.worldX;
|
// Use bone as registration point.
|
||||||
wrapper.y = bone.worldY;
|
wrapper = new Sprite();
|
||||||
wrapper.rotation = bone.worldRotationX * flipX * flipY;
|
wrapper.transform.colorTransform = new ColorTransform();
|
||||||
wrapper.scaleX = bone.worldScaleX * flipX;
|
wrapper.addChild(bitmap);
|
||||||
wrapper.scaleY = bone.worldScaleY * flipY;
|
wrappers[regionAttachment] = wrapper;
|
||||||
addChild(wrapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wrapper.blendMode = blendModes[slot.data.blendMode.ordinal];
|
||||||
|
|
||||||
|
var colorTransform:ColorTransform = wrapper.transform.colorTransform;
|
||||||
|
colorTransform.redMultiplier = skeleton.r * slot.r * regionAttachment.r;
|
||||||
|
colorTransform.greenMultiplier = skeleton.g * slot.g * regionAttachment.g;
|
||||||
|
colorTransform.blueMultiplier = skeleton.b * slot.b * regionAttachment.b;
|
||||||
|
colorTransform.alphaMultiplier = skeleton.a * slot.a * regionAttachment.a;
|
||||||
|
wrapper.transform.colorTransform = colorTransform;
|
||||||
|
|
||||||
|
var bone:Bone = slot.bone;
|
||||||
|
var flipX:int = skeleton.flipX ? -1 : 1;
|
||||||
|
var flipY:int = skeleton.flipY ? -1 : 1;
|
||||||
|
|
||||||
|
wrapper.x = bone.worldX;
|
||||||
|
wrapper.y = bone.worldY;
|
||||||
|
wrapper.rotation = bone.worldRotationX * flipX * flipY;
|
||||||
|
wrapper.scaleX = bone.worldScaleX * flipX;
|
||||||
|
wrapper.scaleY = bone.worldScaleY * flipY;
|
||||||
|
addChild(wrapper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user