From f5661562ddce0755aae139f53da5ef90927bfab9 Mon Sep 17 00:00:00 2001 From: akdcl Date: Wed, 25 Sep 2013 17:45:01 +0800 Subject: [PATCH] update --- src/createjs.d.ts | 1 + src/dragonBones.js | 154 ++++++++++++++++-------- src/dragonBones.ts | 232 ++++++++++++++++++++----------------- src/dragonBonesCreateJS.js | 15 ++- src/dragonBonesCreateJS.ts | 60 ++++++++-- 5 files changed, 292 insertions(+), 170 deletions(-) diff --git a/src/createjs.d.ts b/src/createjs.d.ts index 0006b368..c7318407 100644 --- a/src/createjs.d.ts +++ b/src/createjs.d.ts @@ -22,6 +22,7 @@ declare module createjs y: number; setTransform(x: number, y: number, scaleX: number, scaleY: number, rotation: number, skewX: number, skewY: number, regX: number, regY: number): DisplayObject; + updateCache(): void; } export class Bitmap extends DisplayObject diff --git a/src/dragonBones.js b/src/dragonBones.js index 8e6d3150..461d20e6 100644 --- a/src/dragonBones.js +++ b/src/dragonBones.js @@ -9,15 +9,24 @@ var dragonBones; (function (geom) { var Point = (function () { function Point(x, y) { + if (typeof x === "undefined") { x = 0; } + if (typeof y === "undefined") { y = 0; } this.x = x; this.y = y; } + Point.prototype.toString = function () { + return "[Point (x=" + this.x + " y=" + this.y + ")]"; + }; return Point; })(); geom.Point = Point; var Rectangle = (function () { function Rectangle(x, y, width, height) { + if (typeof x === "undefined") { x = 0; } + if (typeof y === "undefined") { y = 0; } + if (typeof width === "undefined") { width = 0; } + if (typeof height === "undefined") { height = 0; } this.x = x; this.y = y; this.width = width; @@ -162,9 +171,10 @@ var dragonBones; } var listeners = this._listenersMap[type]; if (listeners) { - for (var i = 0, l = listeners.length; i < length; i++) { + var length = listeners.length; + for (var i = 0; i < length; i++) { if (listeners[i] == listener) { - if (l == 1) { + if (length == 1) { listeners.length = 0; delete this._listenersMap[type]; } else { @@ -189,7 +199,8 @@ var dragonBones; if (listeners) { event.target = this; var listenersCopy = listeners.concat(); - for (var i = 0, l = listenersCopy.length; i < l; i++) { + var length = listeners.length; + for (var i = 0; i < length; i++) { listenersCopy[i](event); } } @@ -290,10 +301,10 @@ var dragonBones; var TimelineState = (function () { function TimelineState() { this.transform = new objects.DBTransform(); - this.pivot = new geom.Point(0, 0); + this.pivot = new geom.Point(); this._durationTransform = new objects.DBTransform(); - this._durationPivot = new geom.Point(0, 0); + this._durationPivot = new geom.Point(); this._durationColor = new geom.ColorTransform(); } TimelineState._borrowObject = function () { @@ -363,6 +374,8 @@ var dragonBones; this._durationPivot.x = 0; this._durationPivot.y = 0; + this._currentFrame = null; + switch (this._timeline.getFrameList().length) { case 0: this._bone._arriveAtFrame(null, this, this._animationState, false); @@ -404,6 +417,7 @@ var dragonBones; var frameIndex; while (!this._currentFrame || playedTime > this._currentFramePosition + this._currentFrameDuration || playedTime < this._currentFramePosition) { if (isArrivedFrame) { + this._bone._arriveAtFrame(this._currentFrame, this, this._animationState, true); } isArrivedFrame = true; if (this._currentFrame) { @@ -538,6 +552,7 @@ var dragonBones; this._bone._updateColor(0, 0, 0, 0, 1, 1, 1, 1, false); } } + this._bone._arriveAtFrame(this._currentFrame, this, this._animationState, false); } if (this._tweenTransform || this._tweenColor) { @@ -603,6 +618,8 @@ var dragonBones; } else { this._bone._updateColor(0, 0, 0, 0, 1, 1, 1, 1, false); } + + this._bone._arriveAtFrame(this._currentFrame, this, this._animationState, false); } } }; @@ -617,7 +634,6 @@ var dragonBones; this._originPivot = null; }; TimelineState.HALF_PI = Math.PI * 0.5; - TimelineState.DOUBLE_PI = Math.PI * 2; TimelineState._pool = []; return TimelineState; @@ -626,6 +642,8 @@ var dragonBones; var AnimationState = (function () { function AnimationState() { + this.loop = 0; + this.layer = 0; this._timelineStates = {}; } AnimationState._borrowObject = function () { @@ -659,7 +677,7 @@ var dragonBones; this._armature = armature; - if (Math.round(this.clip.duration * this.clip.frameRate) < 2) { + if (Math.round(this.clip.duration * this.clip.frameRate) < 2 || timeScale == Infinity) { this.timeScale = 1; this.currentTime = this.totalTime; if (this.loop >= 0) { @@ -672,17 +690,17 @@ var dragonBones; this.currentTime = 0; this.loop = loop; } + this._pauseBeforeFadeInComplete = pauseBeforeFadeInComplete; + this._fadeInTime = fadeInTime * this.timeScale; this._fadeState = 1; this._fadeOutBeginTime = 0; - this._fadeOutWeight = NaN; + this._fadeOutWeight = -1; this._fadeWeight = 0; this._fadeIn = true; this._fadeOut = false; - this.fadeInTime = fadeInTime * this.timeScale; - this.loopCount = -1; this.displayControl = displayControl; this.isPlaying = true; @@ -698,7 +716,7 @@ var dragonBones; AnimationState.prototype.fadeOut = function (fadeOutTime, pause) { if (typeof pause === "undefined") { pause = false; } - if (!isNaN(this._fadeOutWeight)) { + if (!this._armature || this._fadeOutWeight >= 0) { return; } this._fadeState = -1; @@ -811,7 +829,6 @@ var dragonBones; event.animationState = this; this._armature._eventList.push(event); } - ; } if (this._fadeOut) { @@ -826,15 +843,17 @@ var dragonBones; this.currentTime += passedTime * this.timeScale; if (this.isPlaying && !this.isComplete) { + var progress; + var currentLoopCount; if (this._pauseBeforeFadeInComplete) { this._pauseBeforeFadeInComplete = false; this.isPlaying = false; - var progress = 0; - var currentLoopCount = Math.floor(progress); + progress = 0; + currentLoopCount = Math.floor(progress); } else { progress = this.currentTime / this.totalTime; - currentLoopCount = progress; + currentLoopCount = Math.floor(progress); if (currentLoopCount != this.loopCount) { if (this.loopCount == -1) { if (this._armature.hasEventListener(events.AnimationEvent.START)) { @@ -897,7 +916,7 @@ var dragonBones; } if (this._fadeState > 0) { - if (this.fadeInTime == 0) { + if (this._fadeInTime == 0) { this._fadeWeight = 1; this._fadeState = 0; this.isPlaying = true; @@ -907,12 +926,12 @@ var dragonBones; this._armature._eventList.push(event); } } else { - this._fadeWeight = this.currentTime / this.fadeInTime; + this._fadeWeight = this.currentTime / this._fadeInTime; if (this._fadeWeight >= 1) { this._fadeWeight = 1; this._fadeState = 0; if (!this.isPlaying) { - this.currentTime -= this.fadeInTime; + this.currentTime -= this._fadeInTime; } this.isPlaying = true; if (this._armature.hasEventListener(events.AnimationEvent.FADE_IN_COMPLETE)) { @@ -950,7 +969,7 @@ var dragonBones; if (isComplete) { this.isComplete = true; if (this.loop < 0) { - this.fadeOut((this._fadeOutWeight || this.fadeInTime) / this.timeScale, true); + this.fadeOut((this._fadeOutWeight || this._fadeInTime) / this.timeScale, true); } } @@ -995,10 +1014,10 @@ var dragonBones; }; AnimationState.prototype.clear = function () { - this._armature = null; this.clip = null; this.enabled = false; + this._armature = null; this._currentFrame = null; this._mixingTransforms = null; @@ -1015,9 +1034,9 @@ var dragonBones; function Animation(armature) { this._armature = armature; this._animationLayer = []; + this._isPlaying = false; - this.animationList = []; - + this.animationNameList = []; this.tweenEnabled = true; this.timeScale = 1; } @@ -1034,10 +1053,34 @@ var dragonBones; }; Animation.prototype.setAnimationDataList = function (value) { this._animationDataList = value; - this.animationList.length = 0; + this.animationNameList.length = 0; for (var index in this._animationDataList) { - this.animationList[this.animationList.length] = this._animationDataList[index].name; + this.animationNameList[this.animationNameList.length] = this._animationDataList[index].name; + } + }; + + Animation.prototype.getIsPlaying = function () { + return this._isPlaying && !this.getIsComplete(); + }; + + Animation.prototype.getIsComplete = function () { + if (this._lastAnimationState) { + if (!this._lastAnimationState.isComplete) { + return false; + } + var j = this._animationLayer.length; + while (j--) { + var animationStateList = this._animationLayer[j]; + var i = animationStateList.length; + while (i--) { + if (!animationStateList[i].isComplete) { + return false; + } + } + } + return true; } + return false; }; Animation.prototype.dispose = function () { @@ -1055,12 +1098,12 @@ var dragonBones; animationStateList.length = 0; } this._animationLayer.length = 0; - this.animationList.length = 0; + this.animationNameList.length = 0; this._armature = null; this._animationLayer = null; this._animationDataList = null; - this.animationList = null; + this.animationNameList = null; }; Animation.prototype.gotoAndPlay = function (animationName, fadeInTime, duration, loop, layer, group, fadeOutMode, displayControl, pauseFadeOut, pauseFadeIn) { @@ -1171,8 +1214,6 @@ var dragonBones; } } - this._lastAnimationState.advanceTime(0); - return this._lastAnimationState; }; @@ -1415,12 +1456,12 @@ var dragonBones; this.tweenEasing = 0; this.tweenRotate = 0; this.displayIndex = 0; - this.visible = true; this.zOrder = NaN; + this.visible = true; this.global = new DBTransform(); this.transform = new DBTransform(); - this.pivot = new geom.Point(0, 0); + this.pivot = new geom.Point(); } TransformFrame.prototype.dispose = function () { _super.prototype.dispose.call(this); @@ -1473,8 +1514,9 @@ var dragonBones; function TransformTimeline() { _super.call(this); this.originTransform = new DBTransform(); - this.originPivot = new geom.Point(0, 0); + this.originPivot = new geom.Point(); this.offset = 0; + this.transformed = false; } TransformTimeline.prototype.dispose = function () { if (this == TransformTimeline.HIDE_TIMELINE) { @@ -1493,6 +1535,7 @@ var dragonBones; __extends(AnimationData, _super); function AnimationData() { _super.call(this); + this.frameRate = 0; this.loop = 0; this.tweenEasing = NaN; this.fadeInTime = 0; @@ -1999,7 +2042,7 @@ var dragonBones; var animationData = new AnimationData(); animationData.name = animationObject[utils.ConstValues.A_NAME]; animationData.frameRate = frameRate; - animationData.loop = Number(animationObject[utils.ConstValues.A_LOOP]); + animationData.loop = Number(animationObject[utils.ConstValues.A_LOOP]) || 0; animationData.fadeInTime = Number(animationObject[utils.ConstValues.A_FADE_IN_TIME]); animationData.duration = Number(animationObject[utils.ConstValues.A_DURATION]) / frameRate; animationData.scale = Number(animationObject[utils.ConstValues.A_SCALE]); @@ -2516,8 +2559,8 @@ var dragonBones; var originTransform; var originPivot; var prevFrame; - var frameListLength; var frame; + var frameListLength; while (i--) { boneData = boneDataList[i]; @@ -2695,6 +2738,11 @@ var dragonBones; this._globalTransformMatrix = new geom.Matrix(); this._visible = true; + this._isColorChanged = false; + this._isDisplayOnStage = false; + this._scaleType = 0; + + this.fixedRotation = false; } DBObject.prototype.getVisible = function () { return this._visible; @@ -2799,7 +2847,7 @@ var dragonBones; Slot.prototype.getDisplay = function () { var display = this._displayList[this._displayIndex]; if (display instanceof Armature) { - return (display).display; + return (display).getDisplay(); } return display; }; @@ -2818,7 +2866,7 @@ var dragonBones; Slot.prototype.setChildArmature = function (value) { this._displayList[this._displayIndex] = value; if (value) { - this._setDisplay(value.display); + this._setDisplay(value.getDisplay()); } }; @@ -2846,7 +2894,7 @@ var dragonBones; } else { this._displayBridge.setDisplay(display); if (this.armature) { - this._displayBridge.addDisplay(this.armature.display, -1); + this._displayBridge.addDisplay(this.armature.getDisplay(), -1); this.armature._slotsZOrderChanged = true; } } @@ -2872,7 +2920,7 @@ var dragonBones; this._isHideDisplay = false; var changeShowState = true; if (this.armature) { - this._displayBridge.addDisplay(this.armature.display, -1); + this._displayBridge.addDisplay(this.armature.getDisplay(), -1); this.armature._slotsZOrderChanged = true; } } @@ -2886,7 +2934,7 @@ var dragonBones; var display = this._displayList[this._displayIndex]; if (display instanceof Armature) { - this._setDisplay((display).display); + this._setDisplay((display).getDisplay()); } else { this._setDisplay(display); } @@ -2917,7 +2965,7 @@ var dragonBones; _super.prototype._setArmature.call(this, value); if (this.armature) { this.armature._slotsZOrderChanged = true; - this._displayBridge.addDisplay(this.armature.display, -1); + this._displayBridge.addDisplay(this.armature.getDisplay(), -1); } else { this._displayBridge.removeDisplay(); } @@ -2964,8 +3012,9 @@ var dragonBones; childArmature.animation.stop(); childArmature.animation._lastAnimationState = null; } else { - if (this.armature && this.armature.animation.getLastAnimationName() && childArmature.animation.hasAnimation(this.armature.animation.getLastAnimationName())) { - childArmature.animation.gotoAndPlay(this.armature.animation.getLastAnimationName()); + var lastAnimationName = this.armature ? this.armature.animation.getLastAnimationName() : null; + if (lastAnimationName && childArmature.animation.hasAnimation(lastAnimationName)) { + childArmature.animation.gotoAndPlay(lastAnimationName); } else { childArmature.animation.play(); } @@ -2983,7 +3032,7 @@ var dragonBones; this._children = []; this._scaleType = 2; - this._tweenPivot = new geom.Point(0, 0); + this._tweenPivot = new geom.Point(); this.scaleMode = 1; } @@ -3072,7 +3121,7 @@ var dragonBones; child._setParent(null); child._setArmature(null); - if (this.slot && child == this.slot) { + if (child == this.slot) { this.slot = null; } } else { @@ -3160,22 +3209,26 @@ var dragonBones; function Armature(display) { _super.call(this); - this.display = display; this.animation = new animation.Animation(this); + this._display = display; this._slotsZOrderChanged = false; this._slotList = []; this._boneList = []; this._eventList = []; } + Armature.prototype.getDisplay = function () { + return this._display; + }; + Armature.prototype.dispose = function () { if (!this.animation) { return; } this.animation.dispose(); - var i = this._slotList.length; + var i = this._slotList.length; while (i--) { this._slotList[i].dispose(); } @@ -3189,16 +3242,17 @@ var dragonBones; this._boneList.length = 0; this._eventList.length = 0; - this.animation = null; this._slotList = null; this._boneList = null; this._eventList = null; + this._display = null; - this.display = null; + this.animation = null; }; Armature.prototype.advanceTime = function (passedTime) { this.animation.advanceTime(passedTime); + passedTime *= this.animation.timeScale; var i = this._boneList.length; while (i--) { @@ -3225,8 +3279,8 @@ var dragonBones; } if (this._eventList.length) { - i = this._eventList.length; - while (i--) { + var length = this._eventList.length; + for (i = 0; i < length; i++) { this.dispatchEvent(this._eventList[i]); } this._eventList.length = 0; @@ -3356,7 +3410,7 @@ var dragonBones; while (i--) { slot = this._slotList[i]; if (slot._isDisplayOnStage) { - slot._displayBridge.addDisplay(this.display, -1); + slot._displayBridge.addDisplay(this._display, -1); } } diff --git a/src/dragonBones.ts b/src/dragonBones.ts index 4f7e4938..8d7accfb 100644 --- a/src/dragonBones.ts +++ b/src/dragonBones.ts @@ -7,11 +7,16 @@ module dragonBones public x: number; public y: number; - constructor(x:number, y:number) + constructor(x:number = 0, y:number = 0) { this.x = x; this.y = y; } + + public toString(): string + { + return "[Point (x=" + this.x + " y=" + this.y + ")]"; + } } export class Rectangle @@ -21,7 +26,7 @@ module dragonBones public width: number; public height: number; - constructor(x:number, y:number, width:number, height:number) + constructor(x:number = 0, y:number = 0, width:number = 0, height:number = 0) { this.x = x; this.y = y; @@ -210,12 +215,14 @@ module dragonBones return; } var listeners: Array = this._listenersMap[type]; - if (listeners) { - for (var i: number = 0, l = listeners.length; i < length; i++) + if (listeners) + { + var length: number = listeners.length; + for (var i: number = 0;i < length; i++) { if (listeners[i] == listener) { - if (l == 1) + if (length == 1) { listeners.length = 0; delete this._listenersMap[type]; @@ -250,7 +257,8 @@ module dragonBones { event.target = this; var listenersCopy: Array = listeners.concat(); - for (var i: number = 0, l = listenersCopy.length; i < l; i++) + var length: number = listeners.length; + for (var i: number = 0; i < length; i++) { listenersCopy[i](event); } @@ -381,7 +389,6 @@ module dragonBones export class TimelineState { private static HALF_PI: number = Math.PI * 0.5; - private static DOUBLE_PI: number = Math.PI * 2; private static _pool:Array = []; @@ -463,10 +470,10 @@ module dragonBones constructor() { this.transform = new objects.DBTransform(); - this.pivot = new geom.Point(0, 0); + this.pivot = new geom.Point(); this._durationTransform = new objects.DBTransform(); - this._durationPivot = new geom.Point(0, 0); + this._durationPivot = new geom.Point(); this._durationColor = new geom.ColorTransform(); } @@ -500,13 +507,15 @@ module dragonBones this._durationTransform.skewX = 0; this._durationTransform.skewY = 0; this._durationPivot.x = 0; - this._durationPivot.y = 0; + this._durationPivot.y = 0; + + this._currentFrame = null; switch(this._timeline.getFrameList().length) { case 0: this._bone._arriveAtFrame(null, this, this._animationState, false); - this._updateState = 0; + this._updateState = 0; break; case 1: this._updateState = -1; @@ -554,7 +563,7 @@ module dragonBones { if(isArrivedFrame) { - //this._bone._arriveAtFrame(this._currentFrame, this, this._animationState, true); + this._bone._arriveAtFrame(this._currentFrame, this, this._animationState, true); } isArrivedFrame = true; if(this._currentFrame) @@ -760,7 +769,7 @@ module dragonBones this._bone._updateColor(0, 0, 0, 0, 1, 1, 1, 1, false); } } - //this._bone._arriveAtFrame(this._currentFrame, this, this._animationState, false); + this._bone._arriveAtFrame(this._currentFrame, this, this._animationState, false); } if(this._tweenTransform || this._tweenColor) @@ -835,7 +844,7 @@ module dragonBones } } else - { + { this._updateState = 0; if(this._animationState.blend) { @@ -880,7 +889,7 @@ module dragonBones this._bone._updateColor(0, 0, 0, 0, 1, 1, 1, 1, false); } - //this._bone._arriveAtFrame(this._currentFrame, this, this._animationState, false); + this._bone._arriveAtFrame(this._currentFrame, this, this._animationState, false); } } } @@ -939,20 +948,19 @@ module dragonBones public group: string; public weight: number; - public name:string; - public clip:objects.AnimationData; - public loopCount: number; + public name: string; + public clip: objects.AnimationData; + public loopCount: number; public loop: number; public layer: number; public isPlaying: boolean; public isComplete: boolean; - public fadeInTime: number; public totalTime: number; - public currentTime: number; - public timeScale: number; - public displayControl:boolean; + public currentTime: number; + public timeScale: number; + public displayControl: boolean; /** @private */ public _timelineStates: any; @@ -963,6 +971,7 @@ module dragonBones private _currentFrame: objects.Frame; private _mixingTransforms: any; private _fadeState: number; + private _fadeInTime: number; private _fadeOutTime: number; private _fadeOutBeginTime: number; private _fadeOutWeight: number; @@ -972,6 +981,8 @@ module dragonBones constructor() { + this.loop = 0; + this.layer = 0; this._timelineStates = {}; } @@ -982,13 +993,12 @@ module dragonBones this.name = this.clip.name; this.totalTime = this.clip.duration; - this._armature = armature; - - //||this.timeScale == Infinity - if(Math.round(this.clip.duration * this.clip.frameRate) < 2) + this._armature = armature; + + if(Math.round(this.clip.duration * this.clip.frameRate) < 2 || timeScale == Infinity) { this.timeScale = 1; - this.currentTime = this.totalTime; + this.currentTime = this.totalTime; if(this.loop >= 0) { this.loop = 1; @@ -1003,22 +1013,23 @@ module dragonBones this.timeScale = timeScale; this.currentTime = 0; this.loop = loop; - } + } + + this._pauseBeforeFadeInComplete = pauseBeforeFadeInComplete; + this._fadeInTime = fadeInTime * this.timeScale; this._fadeState = 1; this._fadeOutBeginTime = 0; - this._fadeOutWeight = NaN; + this._fadeOutWeight = -1; this._fadeWeight = 0; this._fadeIn = true; this._fadeOut = false; - this.fadeInTime = fadeInTime * this.timeScale; - this.loopCount = -1; this.displayControl = displayControl; this.isPlaying = true; - this.isComplete = false; + this.isComplete = false; this.weight = 1; this.blend = true; @@ -1030,10 +1041,10 @@ module dragonBones public fadeOut(fadeOutTime:number, pause:boolean = false):void { - if(!isNaN(this._fadeOutWeight)) + if(!this._armature || this._fadeOutWeight >= 0) { return; - } + } this._fadeState = -1; this._fadeOutWeight = this._fadeWeight; this._fadeOutTime = fadeOutTime * this.timeScale; @@ -1167,11 +1178,11 @@ module dragonBones { this._fadeIn = false; if(this._armature.hasEventListener(events.AnimationEvent.FADE_IN)) - { + { event = new events.AnimationEvent(events.AnimationEvent.FADE_IN); event.animationState = this; this._armature._eventList.push(event); - }; + } } if(this._fadeOut) @@ -1186,21 +1197,23 @@ module dragonBones } this.currentTime += passedTime * this.timeScale; - + if(this.isPlaying && !this.isComplete) { + var progress: number; + var currentLoopCount: number; if(this._pauseBeforeFadeInComplete) { this._pauseBeforeFadeInComplete = false; this.isPlaying = false; - var progress:number = 0; - var currentLoopCount: number = Math.floor(progress); + progress = 0; + currentLoopCount = Math.floor(progress); } else { progress = this.currentTime / this.totalTime; //update loopCount - currentLoopCount = progress; + currentLoopCount = Math.floor(progress); if(currentLoopCount != this.loopCount) { if(this.loopCount == -1) @@ -1214,7 +1227,7 @@ module dragonBones } this.loopCount = currentLoopCount; if(this.loopCount) - { + { if(this.loop && this.loopCount * this.loopCount >= this.loop * this.loop - 1) { isComplete = true; @@ -1283,9 +1296,9 @@ module dragonBones //update weight and fadeState if(this._fadeState > 0) { - if(this.fadeInTime == 0) + if(this._fadeInTime == 0) { - this._fadeWeight = 1; + this._fadeWeight = 1; this._fadeState = 0; this.isPlaying = true; if(this._armature.hasEventListener(events.AnimationEvent.FADE_IN_COMPLETE)) @@ -1297,14 +1310,14 @@ module dragonBones } else { - this._fadeWeight = this.currentTime / this.fadeInTime; + this._fadeWeight = this.currentTime / this._fadeInTime; if(this._fadeWeight >= 1) { this._fadeWeight = 1; this._fadeState = 0; if(!this.isPlaying) { - this.currentTime -= this.fadeInTime; + this.currentTime -= this._fadeInTime; } this.isPlaying = true; if(this._armature.hasEventListener(events.AnimationEvent.FADE_IN_COMPLETE)) @@ -1350,12 +1363,12 @@ module dragonBones if(isComplete) { - this.isComplete = true; + this.isComplete = true; if(this.loop < 0) { - this.fadeOut((this._fadeOutWeight || this.fadeInTime) / this.timeScale, true); + this.fadeOut((this._fadeOutWeight || this._fadeInTime) / this.timeScale, true); } - } + } return false; } @@ -1412,10 +1425,10 @@ module dragonBones private clear():void { - this._armature = null; this.clip = null; this.enabled = false; - + + this._armature = null; this._currentFrame = null; this._mixingTransforms = null; @@ -1437,7 +1450,7 @@ module dragonBones public tweenEnabled: boolean; public timeScale: number; - public animationList: Array; + public animationNameList: Array; /** @private */ public _animationLayer:Array>; @@ -1465,32 +1478,32 @@ module dragonBones public setAnimationDataList(value:Array):void { this._animationDataList = value; - this.animationList.length = 0; + this.animationNameList.length = 0; for(var index in this._animationDataList) { - this.animationList[this.animationList.length] = this._animationDataList[index].name; + this.animationNameList[this.animationNameList.length] = this._animationDataList[index].name; } } - /* - public function get isPlaying():Boolean + + public getIsPlaying():boolean { - return _isPlaying && !isComplete; + return this._isPlaying && !this.getIsComplete(); } - - public function get isComplete():Boolean + + public getIsComplete():boolean { - if(_lastAnimationState) + if(this._lastAnimationState) { - if(!_lastAnimationState.isComplete) + if(!this._lastAnimationState.isComplete) { return false; } - var j:int = _animationLayer.length; + var j:number = this._animationLayer.length; while(j --) { - var animationStateList:Vector. = _animationLayer[j]; - var i:int = animationStateList.length; + var animationStateList:Array = this._animationLayer[j]; + var i:number = animationStateList.length; while(i --) { if(!animationStateList[i].isComplete) @@ -1503,15 +1516,14 @@ module dragonBones } return false; } - */ constructor(armature:Armature) { this._armature = armature; this._animationLayer = []; + this._isPlaying = false; - this.animationList = []; - + this.animationNameList = []; this.tweenEnabled = true; this.timeScale = 1; } @@ -1535,12 +1547,12 @@ module dragonBones animationStateList.length = 0; } this._animationLayer.length = 0; - this.animationList.length = 0; + this.animationNameList.length = 0; this._armature = null; this._animationLayer = null; this._animationDataList = null; - this.animationList = null; + this.animationNameList = null; } public gotoAndPlay( @@ -1674,8 +1686,6 @@ module dragonBones } } - this._lastAnimationState.advanceTime(0); - return this._lastAnimationState; } @@ -1969,8 +1979,8 @@ module dragonBones public tweenEasing:number; public tweenRotate:number; public displayIndex:number; - public visible:boolean; public zOrder:number; + public visible:boolean; public global:DBTransform; public transform:DBTransform; @@ -1984,12 +1994,12 @@ module dragonBones this.tweenEasing = 0; this.tweenRotate = 0; this.displayIndex = 0; - this.visible = true; this.zOrder = NaN; + this.visible = true; this.global = new DBTransform(); this.transform = new DBTransform(); - this.pivot = new geom.Point(0, 0); + this.pivot = new geom.Point(); } public dispose():void @@ -2065,8 +2075,9 @@ module dragonBones { super(); this.originTransform = new DBTransform(); - this.originPivot = new geom.Point(0, 0); - this.offset = 0; + this.originPivot = new geom.Point(); + this.offset = 0; + this.transformed = false; } public dispose():void @@ -2098,6 +2109,7 @@ module dragonBones constructor() { super(); + this.frameRate = 0; this.loop = 0; this.tweenEasing = NaN; this.fadeInTime = 0; @@ -2762,7 +2774,7 @@ module dragonBones var animationData:AnimationData = new AnimationData(); animationData.name = animationObject[utils.ConstValues.A_NAME]; animationData.frameRate = frameRate; - animationData.loop = Number(animationObject[utils.ConstValues.A_LOOP]); + animationData.loop = Number(animationObject[utils.ConstValues.A_LOOP]) || 0; animationData.fadeInTime = Number(animationObject[utils.ConstValues.A_FADE_IN_TIME]); animationData.duration = Number(animationObject[utils.ConstValues.A_DURATION]) / frameRate; animationData.scale = Number(animationObject[utils.ConstValues.A_SCALE]); @@ -3330,7 +3342,7 @@ module dragonBones TransformUtil.transformToMatrix(parent, helpMatrix); helpMatrix.invert(); - var x:number = transform.x; + var x: number = transform.x; var y: number = transform.y; transform.x = helpMatrix.a * x + helpMatrix.c * y + helpMatrix.tx; @@ -3417,8 +3429,8 @@ module dragonBones var originTransform:objects.DBTransform; var originPivot:geom.Point; var prevFrame:objects.TransformFrame; - var frameListLength:number; var frame:objects.TransformFrame; + var frameListLength:number; while(i --) { @@ -3683,6 +3695,11 @@ module dragonBones this._globalTransformMatrix = new geom.Matrix(); this._visible = true; + this._isColorChanged = false; + this._isDisplayOnStage = false; + this._scaleType = 0; + + this.fixedRotation = false; } public dispose(): void @@ -3750,11 +3767,11 @@ module dragonBones /** @private */ public _displayBridge: display.IDisplayBridge; /** @private */ + public _isDisplayOnStage: boolean; + /** @private */ public _originZOrder: number; /** @private */ public _tweenZorder: number; - /** @private */ - public _isDisplayOnStage: boolean; private _isHideDisplay: boolean; private _offsetZOrder: number; @@ -3782,7 +3799,7 @@ module dragonBones var display: any = this._displayList[this._displayIndex]; if (display instanceof Armature) { - return ( display).display; + return ( display).getDisplay(); } return display; } @@ -3806,7 +3823,7 @@ module dragonBones this._displayList[this._displayIndex] = value; if (value) { - this._setDisplay(value.display); + this._setDisplay(value.getDisplay()); } } @@ -3846,7 +3863,7 @@ module dragonBones this._displayBridge.setDisplay(display); if (this.armature) { - this._displayBridge.addDisplay(this.armature.display, -1); + this._displayBridge.addDisplay(this.armature.getDisplay(), -1); this.armature._slotsZOrderChanged = true; } } @@ -3883,7 +3900,7 @@ module dragonBones var changeShowState: boolean = true; if (this.armature) { - this._displayBridge.addDisplay(this.armature.display, -1); + this._displayBridge.addDisplay(this.armature.getDisplay(), -1); this.armature._slotsZOrderChanged = true; } } @@ -3900,7 +3917,7 @@ module dragonBones var display: any = this._displayList[this._displayIndex]; if(display instanceof Armature) { - this._setDisplay(( display).display); + this._setDisplay(( display).getDisplay()); } else { @@ -3944,7 +3961,7 @@ module dragonBones if (this.armature) { this.armature._slotsZOrderChanged = true; - this._displayBridge.addDisplay(this.armature.display, -1); + this._displayBridge.addDisplay(this.armature.getDisplay(), -1); } else { @@ -4021,14 +4038,11 @@ module dragonBones childArmature.animation._lastAnimationState = null; } else - { - if( - this.armature && - this.armature.animation.getLastAnimationName() && - childArmature.animation.hasAnimation(this.armature.animation.getLastAnimationName()) - ) + { + var lastAnimationName: string = this.armature?this.armature.animation.getLastAnimationName():null; + if(lastAnimationName && childArmature.animation.hasAnimation(lastAnimationName)) { - childArmature.animation.gotoAndPlay(this.armature.animation.getLastAnimationName()); + childArmature.animation.gotoAndPlay(lastAnimationName); } else { @@ -4087,7 +4101,7 @@ module dragonBones this._children = []; this._scaleType = 2; - this._tweenPivot = new geom.Point(0, 0); + this._tweenPivot = new geom.Point(); this.scaleMode = 1; } @@ -4171,7 +4185,7 @@ module dragonBones child._setParent(null); child._setArmature(null); - if(this.slot && child == this.slot) + if(child == this.slot) { this.slot = null; } @@ -4308,7 +4322,6 @@ module dragonBones public name: string; - public display: any; public animation: animation.Animation; /** @private */ @@ -4320,13 +4333,19 @@ module dragonBones /** @private */ public _eventList: Array; + private _display: any; + public getDisplay(): any + { + return this._display; + } + constructor(display:any) { super(); - this.display = display; this.animation = new animation.Animation(this); - + + this._display = display; this._slotsZOrderChanged = false; this._slotList = []; this._boneList = []; @@ -4340,9 +4359,9 @@ module dragonBones return; } - this.animation.dispose(); - var i: number = this._slotList.length; + this.animation.dispose(); + var i: number = this._slotList.length; while(i --) { this._slotList[i].dispose(); @@ -4358,18 +4377,19 @@ module dragonBones this._boneList.length = 0; this._eventList.length = 0; - this.animation = null; this._slotList = null; this._boneList = null; this._eventList = null; + this._display = null; - this.display = null; + this.animation = null; } public advanceTime(passedTime: number): void { this.animation.advanceTime(passedTime); - + passedTime *= this.animation.timeScale; + var i:number = this._boneList.length; while(i --) { @@ -4402,8 +4422,8 @@ module dragonBones if(this._eventList.length) { - i = this._eventList.length; - while(i --) + var length = this._eventList.length; + for (i = 0;i < length;i ++) { this.dispatchEvent(this._eventList[i]); } @@ -4576,7 +4596,7 @@ module dragonBones slot = this._slotList[i]; if(slot._isDisplayOnStage) { - slot._displayBridge.addDisplay(this.display, -1); + slot._displayBridge.addDisplay(this._display, -1); } } diff --git a/src/dragonBonesCreateJS.js b/src/dragonBonesCreateJS.js index 1da296d5..11eef56c 100644 --- a/src/dragonBonesCreateJS.js +++ b/src/dragonBonesCreateJS.js @@ -42,8 +42,8 @@ var dragonBones; }; CreateJSDisplayBridge.prototype.updateTransform = function (matrix, transform) { - this._display.x = transform.x; - this._display.y = transform.y; + this._display.x = matrix.tx; + this._display.y = matrix.ty; this._display.skewX = transform.skewX * CreateJSDisplayBridge.RADIAN_TO_ANGLE; this._display.skewY = transform.skewY * CreateJSDisplayBridge.RADIAN_TO_ANGLE; this._display.scaleX = transform.scaleX; @@ -51,6 +51,9 @@ var dragonBones; }; CreateJSDisplayBridge.prototype.updateColor = function (aOffset, rOffset, gOffset, bOffset, aMultiplier, rMultiplier, gMultiplier, bMultiplier) { + if (this._display) { + this._display.alpha = aMultiplier; + } }; CreateJSDisplayBridge.prototype.addDisplay = function (container, index) { @@ -78,10 +81,12 @@ var dragonBones; (function (textures) { var CreateJSTextureAtlas = (function () { - function CreateJSTextureAtlas(image, textureAtlasRawData) { + function CreateJSTextureAtlas(image, textureAtlasRawData, scale) { + if (typeof scale === "undefined") { scale = 1; } this._regions = {}; this.image = image; + this.scale = scale; this.parseData(textureAtlasRawData); } @@ -95,7 +100,7 @@ var dragonBones; }; CreateJSTextureAtlas.prototype.parseData = function (textureAtlasRawData) { - var textureAtlasData = dragonBones.objects.DataParser.parseTextureAtlasData(textureAtlasRawData, 1); + var textureAtlasData = dragonBones.objects.DataParser.parseTextureAtlasData(textureAtlasRawData, this.scale); this.name = textureAtlasData.__name; delete textureAtlasData.__name; @@ -133,7 +138,7 @@ var dragonBones; CreateJSFactory._helpMatrix.b = 0; CreateJSFactory._helpMatrix.c = 0; CreateJSFactory._helpMatrix.d = 1; - + CreateJSFactory._helpMatrix.scale(1 / textureAtlas.scale, 1 / textureAtlas.scale); CreateJSFactory._helpMatrix.tx = -pivotX - rect.x; CreateJSFactory._helpMatrix.ty = -pivotY - rect.y; shape.graphics.beginBitmapFill(textureAtlas.image, null, CreateJSFactory._helpMatrix); diff --git a/src/dragonBonesCreateJS.ts b/src/dragonBonesCreateJS.ts index 56b1f386..f5cf1c08 100644 --- a/src/dragonBonesCreateJS.ts +++ b/src/dragonBonesCreateJS.ts @@ -10,7 +10,6 @@ module dragonBones private static RADIAN_TO_ANGLE: number = 180 / Math.PI; private _display: createjs.DisplayObject; - private _colorFilter: createjs.ColorFilter; public getVisible(): boolean { @@ -58,7 +57,8 @@ module dragonBones public updateTransform(matrix: geom.Matrix, transform: objects.DBTransform): void { - /*var pivotX:number = this._display.regX; + /* + var pivotX:number = this._display.regX; var pivotY:number = this._display.regY; matrix.tx -= matrix.a * pivotX + matrix.c * pivotY; matrix.ty -= matrix.b * pivotX + matrix.d * pivotY; @@ -68,10 +68,11 @@ module dragonBones this._display._matrix.c = matrix.c; this._display._matrix.d = matrix.d; this._display._matrix.tx = matrix.tx; - this._display._matrix.ty = matrix.ty;*/ + this._display._matrix.ty = matrix.ty; + */ - this._display.x = transform.x; - this._display.y = transform.y; + this._display.x = matrix.tx; + this._display.y = matrix.ty; this._display.skewX = transform.skewX * CreateJSDisplayBridge.RADIAN_TO_ANGLE; this._display.skewY = transform.skewY * CreateJSDisplayBridge.RADIAN_TO_ANGLE; this._display.scaleX = transform.scaleX; @@ -80,7 +81,46 @@ module dragonBones public updateColor(aOffset: number, rOffset: number, gOffset: number, bOffset: number, aMultiplier: number, rMultiplier: number, gMultiplier: number, bMultiplier: number): void { - + if(this._display) + { + /*var filters: Array = this._display.filters; + if(!filters) + { + this._display.filters = filters = []; + } + var colorFilter: createjs.ColorFilter; + if (filters.length > 0) + { + for (var index in filters) + { + if (filters[index] instanceof createjs.ColorFilter) + { + colorFilter = filters[index]; + break; + } + } + } + if (colorFilter) + { + colorFilter.alphaMultiplier = aMultiplier; + colorFilter.redMultiplier = rMultiplier; + colorFilter.greenMultiplier = gMultiplier; + colorFilter.blueMultiplier = bMultiplier; + colorFilter.alphaOffset = aOffset; + colorFilter.redOffset = rOffset; + colorFilter.greenOffset = gOffset; + colorFilter.blueOffset = bOffset; + } + else + { + colorFilter = new createjs.ColorFilter(rMultiplier, gMultiplier, bMultiplier, aMultiplier, rOffset, gOffset, bOffset, aOffset); + filters.push(colorFilter); + } + this._display.updateCache();*/ + + // + this._display.alpha = aMultiplier; + } } public addDisplay(container: any, index: number): void @@ -116,14 +156,16 @@ module dragonBones public name: string; //{HTMLImageElement | HTMLCanvasElement | HTMLVideoElement} public image: any; + public scale: number; private _regions: any; - constructor(image:any, textureAtlasRawData:any) + constructor(image:any, textureAtlasRawData:any, scale:number = 1) { this._regions = {}; this.image = image; + this.scale = scale; this.parseData(textureAtlasRawData); } @@ -141,7 +183,7 @@ module dragonBones private parseData(textureAtlasRawData:any):void { - var textureAtlasData: any = objects.DataParser.parseTextureAtlasData(textureAtlasRawData, 1); + var textureAtlasData: any = objects.DataParser.parseTextureAtlasData(textureAtlasRawData, this.scale); this.name = textureAtlasData.__name; delete textureAtlasData.__name; @@ -189,7 +231,7 @@ module dragonBones CreateJSFactory._helpMatrix.b = 0; CreateJSFactory._helpMatrix.c = 0; CreateJSFactory._helpMatrix.d = 1; - //_helpMatirx.scale(nativeTextureAtlas.scale, nativeTextureAtlas.scale); + CreateJSFactory._helpMatrix.scale(1 / textureAtlas.scale, 1 / textureAtlas.scale); CreateJSFactory._helpMatrix.tx = -pivotX - rect.x; CreateJSFactory._helpMatrix.ty = -pivotY - rect.y; shape.graphics.beginBitmapFill(textureAtlas.image, null, CreateJSFactory._helpMatrix);