Skip to content

Commit 7483cef

Browse files
author
Chenguang Liu
committed
Merge remote-tracking branch 'origin/dev'
2 parents 577fa87 + d281a21 commit 7483cef

File tree

9 files changed

+108
-53
lines changed

9 files changed

+108
-53
lines changed

src/dragonBones/Armature.as

+7-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ package dragonBones
8585
*
8686
* private function updateAnimation(e:Event):void
8787
* {
88-
* armature.advanceTime(stage.frameRate / 1000);
88+
* armature.advanceTime(1 / stage.frameRate);
8989
* }
9090
* }
9191
* }
@@ -307,8 +307,10 @@ package dragonBones
307307
*/
308308
public function advanceTime(passedTime:Number):void
309309
{
310-
for each(var bone:Bone in _boneDepthList)
310+
var i:int = _boneDepthList.length;
311+
while(i --)
311312
{
313+
var bone:Bone = _boneDepthList[i];
312314
if(bone._isOnStage)
313315
{
314316
var childArmature:Armature = bone.childArmature;
@@ -346,9 +348,10 @@ package dragonBones
346348
/** @private */
347349
dragonBones_internal function update():void
348350
{
349-
for each(var bone:Bone in _rootBoneList)
351+
var i:int = _rootBoneList.length;
352+
while(i --)
350353
{
351-
bone.update();
354+
_rootBoneList[i].update();
352355
}
353356

354357
_colorTransformChange = false;

src/dragonBones/Bone.as

+45-26
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import flash.events.EventDispatcher;
1616
import flash.geom.ColorTransform;
1717
import flash.geom.Matrix;
18-
import flash.geom.Point;
1918

2019
use namespace dragonBones_internal;
2120

@@ -59,7 +58,7 @@
5958
*
6059
* private function updateAnimation(e:Event):void
6160
* {
62-
* armature.advanceTime(stage.frameRate / 1000);
61+
* armature.advanceTime(1 / stage.frameRate);
6362
* }
6463
* }
6564
* }
@@ -69,7 +68,6 @@
6968
*/
7069
public class Bone extends EventDispatcher
7170
{
72-
private static var _helpPoint:Point = new Point();
7371
/**
7472
* The name of this Bone instance's Armature instance.
7573
*/
@@ -192,9 +190,6 @@
192190
{
193191
return _displayBridge.display;
194192
}
195-
/**
196-
* @private
197-
*/
198193
public function set display(value:Object):void
199194
{
200195
if(_displayBridge.display == value)
@@ -209,16 +204,32 @@
209204
_displayBridge.display = value;
210205
}
211206

207+
208+
/**
209+
* The DisplayObject list belonging to this Bone instance.
210+
*/
211+
public function get displayList():Array
212+
{
213+
return _displayList;
214+
}
215+
212216
/** @private */
213217
dragonBones_internal function changeDisplay(displayIndex:int):void
214218
{
219+
var childArmature:Armature = this.childArmature;
215220
if(displayIndex < 0)
216221
{
217222
if(_isOnStage)
218223
{
219224
_isOnStage = false;
220225
//removeFromStage
221226
_displayBridge.removeDisplay();
227+
228+
if(childArmature)
229+
{
230+
childArmature.animation.stop();
231+
childArmature.animation.clearMovement();
232+
}
222233
}
223234
}
224235
else
@@ -245,6 +256,11 @@
245256
//change
246257
display = _displayList[_displayIndex];
247258
}
259+
260+
if(childArmature)
261+
{
262+
childArmature.animation.play();
263+
}
248264
}
249265
}
250266

@@ -368,42 +384,45 @@
368384
/** @private */
369385
dragonBones_internal function update():void
370386
{
387+
//transform
388+
if(_parent)
389+
{
390+
var x:Number = origin.x + node.x + _tweenNode.x;
391+
var y:Number = origin.y + node.y + _tweenNode.y;
392+
var parentMatrix:Matrix = _parent._globalTransformMatrix;
393+
_globalTransformMatrix.tx = global.x = parentMatrix.a * x + parentMatrix.c * y + parentMatrix.tx;
394+
_globalTransformMatrix.ty = global.y = parentMatrix.d * y + parentMatrix.b * x + parentMatrix.ty;
395+
global.skewX = _parent.global.skewX + origin.skewX + node.skewX + _tweenNode.skewX;
396+
global.skewY = _parent.global.skewY + origin.skewY + node.skewY + _tweenNode.skewY;
397+
}
398+
else
399+
{
400+
_globalTransformMatrix.tx = global.x = origin.x + node.x + _tweenNode.x;
401+
_globalTransformMatrix.ty = global.y = origin.y + node.y + _tweenNode.y;
402+
global.skewX = origin.skewX + node.skewX + _tweenNode.skewX;
403+
global.skewY = origin.skewY + node.skewY + _tweenNode.skewY;
404+
}
405+
371406
//update global
372-
global.x = origin.x + node.x + _tweenNode.x;
373-
global.y = origin.y + node.y + _tweenNode.y;
374-
global.skewX = origin.skewX + node.skewX + _tweenNode.skewX;
375-
global.skewY = origin.skewY + node.skewY + _tweenNode.skewY;
376407
global.scaleX = origin.scaleX + node.scaleX + _tweenNode.scaleX;
377408
global.scaleY = origin.scaleY + node.scaleY + _tweenNode.scaleY;
378409
global.pivotX = origin.pivotX + node.pivotX + _tweenNode.pivotX;
379410
global.pivotY = origin.pivotY + node.pivotY + _tweenNode.pivotY;
380411
global.z = origin.z + node.z + _tweenNode.z;
381-
//transform
382-
if(_parent)
383-
{
384-
_helpPoint.x = global.x;
385-
_helpPoint.y = global.y;
386-
_helpPoint = _parent._globalTransformMatrix.transformPoint(_helpPoint);
387-
global.x = _helpPoint.x
388-
global.y = _helpPoint.y;
389-
global.skewX += _parent.global.skewX;
390-
global.skewY += _parent.global.skewY;
391-
}
392412

393413
//Note: this formula of transform is defined by Flash pro
394414
_globalTransformMatrix.a = global.scaleX * Math.cos(global.skewY);
395415
_globalTransformMatrix.b = global.scaleX * Math.sin(global.skewY);
396416
_globalTransformMatrix.c = -global.scaleY * Math.sin(global.skewX);
397417
_globalTransformMatrix.d = global.scaleY * Math.cos(global.skewX);
398-
_globalTransformMatrix.tx = global.x;
399-
_globalTransformMatrix.ty = global.y;
400418

401419
//update children
402420
if (_children.length > 0)
403421
{
404-
for each(var child:Bone in _children)
422+
var i:int = _children.length;
423+
while(i --)
405424
{
406-
child.update();
425+
_children[i].update();
407426
}
408427
}
409428

@@ -455,4 +474,4 @@
455474
}
456475
}
457476
}
458-
}
477+
}

src/dragonBones/animation/Animation.as

+10-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
*
5858
* private function updateAnimation(e:Event):void
5959
* {
60-
* armature.advanceTime(stage.frameRate / 1000);
60+
* armature.advanceTime(1 / stage.frameRate);
6161
* }
6262
* }
6363
* }
@@ -375,6 +375,12 @@
375375
}
376376
}
377377

378+
/** @private */
379+
dragonBones_internal function clearMovement():void
380+
{
381+
_movementID = null;
382+
}
383+
378384
/**
379385
* Stop the playhead.
380386
*/
@@ -462,9 +468,10 @@
462468
}
463469
}
464470

465-
for each (var bone:Bone in _armature._boneDepthList)
471+
var i:int = _armature._boneDepthList.length;
472+
while(i --)
466473
{
467-
bone._tween.advanceTime(progress, _playType);
474+
_armature._boneDepthList[i]._tween.advanceTime(progress, _playType);
468475
}
469476

470477
if ((_playType == LIST || _playType == LOOP) && _movementData._movementFrameList.length > 0)

src/dragonBones/animation/Tween.as

+4-3
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@
108108
return;
109109
}
110110

111-
_node.skewX %= 360;
112-
_node.skewY %= 360;
111+
_node.skewX %= Math.PI * 2;
112+
_node.skewY %= Math.PI * 2;
113113
_isPause = false;
114114
_currentFrameData = null;
115115
_loop = loop?0:-1;
@@ -131,6 +131,7 @@
131131
{
132132
getLoopListNode();
133133
setOffset(_bone._isOnStage?_node:_offSetNode, _colorTransform, _offSetNode, _offSetColorTransform);
134+
//nextFrameData = _movementBoneData._frameList[0];
134135
}
135136
else
136137
{
@@ -203,7 +204,7 @@
203204
/** @private */
204205
internal function advanceTime(progress:Number, playType:int):void
205206
{
206-
if(_isPause)
207+
if(_isPause || !_movementBoneData)
207208
{
208209
return;
209210
}

src/dragonBones/animation/WorldClock.as

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*
4949
* private function updateAnimation(e:Event):void
5050
* {
51-
* WorldClock.clock.advanceTime(stage.frameRate / 1000);
51+
* WorldClock.clock.advanceTime(1 / stage.frameRate);
5252
* }
5353
* }
5454
* }

src/dragonBones/display/StarlingDisplayBridge.as

+21-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import starling.display.DisplayObject;
1616
import starling.display.DisplayObjectContainer;
1717
import starling.display.Quad;
18+
import starling.display.Image;
1819

1920
/**
2021
* The StarlingDisplayBridge class is an implementation of the IDisplayBridge interface for starling.display.DisplayObject.
@@ -42,6 +43,25 @@
4243
{
4344
return;
4445
}
46+
47+
//Thanks Jian
48+
if (_display is Image && value is Image)
49+
{
50+
var from:Image = _display as Image;
51+
var to:Image = value as Image;
52+
if (from.texture == to.texture)
53+
{
54+
return;
55+
}
56+
57+
from.texture = to.texture;
58+
//update pivot
59+
from.pivotX = to.pivotX;
60+
from.pivotY = to.pivotY;
61+
from.readjustSize();
62+
return;
63+
}
64+
4565
if (_display)
4666
{
4767
var parent:* = _display.parent;
@@ -119,4 +139,4 @@
119139
}
120140
}
121141
}
122-
}
142+
}

src/dragonBones/objects/BoneTransform.as

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ package dragonBones.objects
4848
*
4949
* private function updateAnimation(e:Event):void
5050
* {
51-
* armature.advanceTime(stage.frameRate / 1000);
51+
* armature.advanceTime(1 / stage.frameRate);
5252
* }
5353
* }
5454
* }

src/dragonBones/objects/XMLDataParser.as

+17-10
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@
3131
var version:String = skeletonXML.attribute(ConstValues.A_VERSION);
3232
switch (version)
3333
{
34-
case ConstValues.VERSION_14:
35-
case ConstValues.VERSION_20:
34+
case "1.4":
35+
case "1.5":
36+
case "2.0":
37+
case "2.1":
38+
case "2.1.1":
39+
case "2.1.2":
3640
case ConstValues.VERSION:
3741
break;
3842
default:
@@ -140,7 +144,7 @@
140144
for each (var armatureXML:XML in skeletonXML.elements(ConstValues.ARMATURES).elements(ConstValues.ARMATURE))
141145
{
142146
var armatureName:String = armatureXML.attribute(ConstValues.A_NAME);
143-
var armatureData:ArmatureData = skeletonData.getArmatureData(animationName);
147+
var armatureData:ArmatureData = skeletonData.getArmatureData(armatureName);
144148
if (armatureData)
145149
{
146150
parseArmatureData(armatureXML, armatureData);
@@ -426,12 +430,15 @@
426430

427431
private static function parseMovementFrameData(movementFrameXML:XML, movementFrameData:MovementFrameData):void
428432
{
429-
movementFrameData.setValues(
430-
Number(movementFrameXML.attribute(ConstValues.A_DURATION)) / _currentSkeletonData._frameRate,
431-
movementFrameXML.attribute(ConstValues.A_MOVEMENT),
432-
movementFrameXML.attribute(ConstValues.A_EVENT),
433-
movementFrameXML.attribute(ConstValues.A_SOUND)
434-
);
433+
if(_currentSkeletonData)
434+
{
435+
movementFrameData.setValues(
436+
Number(movementFrameXML.attribute(ConstValues.A_DURATION)) / _currentSkeletonData._frameRate,
437+
movementFrameXML.attribute(ConstValues.A_MOVEMENT),
438+
movementFrameXML.attribute(ConstValues.A_EVENT),
439+
movementFrameXML.attribute(ConstValues.A_SOUND)
440+
);
441+
}
435442
}
436443

437444
/** @private */
@@ -483,4 +490,4 @@
483490
colorTransform.blueMultiplier = int(xml.attribute(ConstValues.A_BLUE_MULTIPLIER)) * 0.01;
484491
}
485492
}
486-
}
493+
}

src/dragonBones/utils/ConstValues.as

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
/** @private */
55
final public class ConstValues
66
{
7-
public static const VERSION_14:String = "1.4";
8-
public static const VERSION_20:String = "2.0";
9-
public static const VERSION:String = "2.1";
7+
public static const VERSION:String = "2.2";
108
public static const SKELETON:String = "skeleton";
119
public static const ARMATURES:String = "armatures";
1210
public static const ARMATURE:String = "armature";
@@ -66,4 +64,4 @@
6664
public static const V_SOUND_FADE_OUT:String = "out";
6765
}
6866

69-
}
67+
}

0 commit comments

Comments
 (0)