Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
akdcl committed Jul 28, 2016
1 parent 76273a5 commit 9a26229
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 194 deletions.
8 changes: 7 additions & 1 deletion DragonBones/src/dragonBones/Armature.as
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ package dragonBones

slot._update(_cacheFrameIndex);

const childArmature:Armature = slot.childArmature;
const childArmature:Armature = slot._childArmature;
if (childArmature)
{
if (slot.inheritAnimation) // Animation's time scale will impact to childArmature
Expand All @@ -397,6 +397,12 @@ package dragonBones
}
}

//
if (DragonBones.DEBUG_DRAW)
{
_display._debugDraw();
}

//
if (_action)
{
Expand Down
53 changes: 30 additions & 23 deletions DragonBones/src/dragonBones/Bone.as
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@
}
else
{
_transformDirty = 1;
_transformDirty = 2;
this.globalTransformMatrix = this._globalTransformMatrix;
}
}
Expand All @@ -488,36 +488,43 @@

if (_transformDirty > 0)
{
_transformDirty--;

if (this.globalTransformMatrix == this._globalTransformMatrix)
if (_transformDirty == 2)
{
this.global.copyFrom(this.origin).add(this.offset).add(_animationPose);
/*this.global.x = this.origin.x + this.offset.x + _animationPose.x;
this.global.y = this.origin.y + this.offset.y + _animationPose.y;
this.global.skewX = this.origin.skewX + this.offset.skewX + _animationPose.skewX;
this.global.skewY = this.origin.skewY + this.offset.skewY + _animationPose.skewY;
this.global.scaleX = this.origin.scaleX * this.offset.scaleX * _animationPose.scaleX;
this.global.scaleY = this.origin.scaleY * this.offset.scaleY * _animationPose.scaleY;*/

_updateGlobalTransformMatrix();
_transformDirty = 1;

if (_ik && _ikChainIndex == _ikChain && ikWeight > 0)
if (this.globalTransformMatrix == this._globalTransformMatrix)
{
if (this.inheritTranslation && _ikChain > 0 && this._parent)
this.global.copyFrom(this.origin).add(this.offset).add(_animationPose);
/*this.global.x = this.origin.x + this.offset.x + _animationPose.x;
this.global.y = this.origin.y + this.offset.y + _animationPose.y;
this.global.skewX = this.origin.skewX + this.offset.skewX + _animationPose.skewX;
this.global.skewY = this.origin.skewY + this.offset.skewY + _animationPose.skewY;
this.global.scaleX = this.origin.scaleX * this.offset.scaleX * _animationPose.scaleX;
this.global.scaleY = this.origin.scaleY * this.offset.scaleY * _animationPose.scaleY;*/

_updateGlobalTransformMatrix();

if (_ik && _ikChainIndex == _ikChain && ikWeight > 0)
{
_computeIKB();
if (this.inheritTranslation && _ikChain > 0 && this._parent)
{
_computeIKB();
}
else
{
_computeIKA();
}
}
else

if (cacheFrameIndex >= 0)
{
_computeIKA();
this.globalTransformMatrix = BoneTimelineData.cacheFrame(_cacheFrames, cacheFrameIndex, this._globalTransformMatrix);
}
}

if (cacheFrameIndex >= 0)
{
this.globalTransformMatrix = BoneTimelineData.cacheFrame(_cacheFrames, cacheFrameIndex, this._globalTransformMatrix);
}
}
else
{
_transformDirty = 0;
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions DragonBones/src/dragonBones/Slot.as
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
dragonBones_internal var _meshData:MeshData;

/**
* @private BoneTimelineState
* @private
*/
dragonBones_internal var _cacheFrames:Vector.<Matrix>;
dragonBones_internal var _childArmature:Armature;

/**
* @private Factory
Expand All @@ -91,6 +91,11 @@
*/
dragonBones_internal var _meshDisplay:Object;

/**
* @private BoneTimelineState
*/
dragonBones_internal var _cacheFrames:Vector.<Matrix>;

/**
* @private SlotTimelineState
*/
Expand Down Expand Up @@ -141,11 +146,6 @@
*/
protected var _display:Object;

/**
* @private
*/
protected var _childArmature:Armature;

/**
* @private
*/
Expand Down Expand Up @@ -221,9 +221,10 @@
_zOrder = 0;
_displayDataSet = null;
_meshData = null;
_cacheFrames = null;
_childArmature = null;
_rawDisplay = null;
_meshDisplay = null;
_cacheFrames = null;
_colorTransform.alphaMultiplier = 1;
_colorTransform.redMultiplier = 1;
_colorTransform.greenMultiplier = 1;
Expand Down Expand Up @@ -254,7 +255,6 @@
_displayIndex = 0;
_blendMode = DragonBones.BLEND_MODE_NORMAL;
_display = null;
_childArmature = null;
_localMatrix.identity();

if (_displayList.length)
Expand Down
7 changes: 6 additions & 1 deletion DragonBones/src/dragonBones/animation/WorldClock.as
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
animateble = _animatebles[i];
if (animateble)
{
if (r > 0)
{
_animatebles[i - r] = animateble;
_animatebles[i] = null;
}

animateble.advanceTime(passedTime);
}
else
Expand All @@ -98,7 +104,6 @@

if (r > 0)
{
r = 0;
l = _animatebles.length;

for (; i < l; ++i)
Expand Down
10 changes: 10 additions & 0 deletions DragonBones/src/dragonBones/core/DragonBones.as
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ package dragonBones.core

public static const VERSION:String = "4.7.1";

/**
* @private
*/
public static var DEBUG:Boolean = true;

/**
* @private
*/
public static var DEBUG_DRAW:Boolean = true;

/**
* @private
*/
Expand Down
6 changes: 6 additions & 0 deletions DragonBones/src/dragonBones/core/IArmatureDisplay.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dragonBones.core
{
import dragonBones.Armature;
import dragonBones.animation.Animation;
import dragonBones.events.EventObject;
import dragonBones.events.IEventDispatcher;

/**
Expand All @@ -12,6 +13,11 @@ package dragonBones.core
*/
public interface IArmatureDisplay extends IEventDispatcher
{
/**
* @private
*/
function _debugDraw():void;

/**
* @language zh_CN
* 由显示容器来更新骨架和动画。
Expand Down
24 changes: 13 additions & 11 deletions DragonBones/src/dragonBones/factories/BaseFactory.as
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,19 @@
}

const slot:Slot = _generateSlot(dataPackage, slotDisplayDataSet);

slot._displayDataSet = slotDisplayDataSet;
slot._setDisplayIndex(slotData.displayIndex);
slot._setBlendMode(slotData.blendMode);
slot._setColor(slotData.color);

slot._replacedDisplayDataSet.fixed = false;
slot._replacedDisplayDataSet.length = slot._displayDataSet.displays.length;
slot._replacedDisplayDataSet.fixed = true;

armature.addSlot(slot, slotData.parent.name);
if (slot)
{
slot._displayDataSet = slotDisplayDataSet;
slot._setDisplayIndex(slotData.displayIndex);
slot._setBlendMode(slotData.blendMode);
slot._setColor(slotData.color);

slot._replacedDisplayDataSet.fixed = false;
slot._replacedDisplayDataSet.length = slot._displayDataSet.displays.length;
slot._replacedDisplayDataSet.fixed = true;

armature.addSlot(slot, slotData.parent.name);
}
}
}

Expand Down
76 changes: 55 additions & 21 deletions DragonBones/src/dragonBones/flash/FlashArmatureDisplay.as
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package dragonBones.flash
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.getTimer;

import dragonBones.Armature;
import dragonBones.Bone;
import dragonBones.animation.Animation;
import dragonBones.animation.WorldClock;
import dragonBones.core.IArmatureDisplay;
import dragonBones.core.dragonBones_internal;
import dragonBones.events.EventObject;
Expand All @@ -16,32 +20,35 @@ package dragonBones.flash
*/
public class FlashArmatureDisplay extends Sprite implements IArmatureDisplay
{
/**
* @private
*/
private var _time:Number;
private static const _enterFrameHelper:Shape = new Shape();
private static const _clock:WorldClock = new WorldClock();
private static function _clockHandler(event:Event):void
{
const time:Number = getTimer() * 0.001;
const passedTime:Number = time - _clock.time;
_clock.advanceTime(passedTime);
_clock.time = time;
}

/**
* @private
*/
dragonBones_internal var _armature:Armature;

private var _debugDrawer:Shape;

/**
* @private
*/
public function FlashArmatureDisplay()
{
super();
}

/**
* @private
*/
private function _advanceTimeHandler(event:Event):void
{
const passedTime:Number = new Date().getTime() * 0.001 - _time;
_time += passedTime;
this._armature.advanceTime(passedTime);

if (!_enterFrameHelper.hasEventListener(Event.ENTER_FRAME))
{
_clock.time = getTimer() * 0.001;
_enterFrameHelper.addEventListener(Event.ENTER_FRAME, _clockHandler, false, -999999);
}
}

/**
Expand All @@ -51,9 +58,8 @@ package dragonBones.flash
{
advanceTimeBySelf(false);

_time = 0;

_armature = null;
_debugDrawer = null;
}

/**
Expand All @@ -66,6 +72,35 @@ package dragonBones.flash
this.dispatchEvent(event);
}

/**
* @inheritDoc
*/
public function _debugDraw():void
{
if (!_debugDrawer)
{
_debugDrawer = new Shape();
}

this.addChild(_debugDrawer);
_debugDrawer.graphics.clear();

const bones:Vector.<Bone> = _armature.getBones();
for (var i:uint = 0, l:uint = bones.length; i < l; ++i)
{
const bone:Bone = bones[i];
const boneLength:Number = Math.max(bone.length, 5);
const startX:Number = bone.globalTransformMatrix.tx;
const startY:Number = bone.globalTransformMatrix.ty;
const endX:Number = startX + bone.globalTransformMatrix.a * boneLength;
const endY:Number = startY + bone.globalTransformMatrix.b * boneLength;

_debugDrawer.graphics.lineStyle(1, bone.ik ? 0xFF0000 : 0x00FF00, 0.5);
_debugDrawer.graphics.moveTo(startX, startY);
_debugDrawer.graphics.lineTo(endX, endY);
}
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -97,12 +132,11 @@ package dragonBones.flash
{
if (on)
{
_time = new Date().getTime() * 0.001;
this.addEventListener(Event.ENTER_FRAME, _advanceTimeHandler);
}
else
_clock.add(this._armature);
}
else
{
this.removeEventListener(Event.ENTER_FRAME, _advanceTimeHandler);
_clock.remove(this._armature);
}
}

Expand Down
Loading

0 comments on commit 9a26229

Please sign in to comment.