@safe-engine/cocos 1.4.3 → 1.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4788 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.dragonBones = void 0;
5
- var dragonBones = dragonBones || {};
6
- exports.dragonBones = dragonBones;
7
- dragonBones.DisplayType = {
8
- DT_IMAGE: 0,
9
- DT_ARMATURE: 1,
10
- DT_FRAME: 2,
11
- DT_TEXT: 3,
12
- DT_1: 4,
13
- DT_2: 5,
14
- DT_3: 6,
15
- DT_4: 7,
16
- DT_5: 8
17
- };
18
- dragonBones.getDisplayTypeByString = function (displayType) {
19
- if (displayType == 'image') {
20
- return dragonBones.DisplayType.DT_IMAGE;
21
- }
22
- else if (displayType == 'armature') {
23
- return dragonBones.DisplayType.DT_ARMATURE;
24
- }
25
- else if (displayType == 'frame') {
26
- return dragonBones.DisplayType.DT_FRAME;
27
- }
28
- else if (displayType == 'text') {
29
- return dragonBones.DisplayType.DT_TEXT;
30
- }
31
- return dragonBones.DisplayType.DT_IMAGE;
32
- };
33
- dragonBones.AnimationFadeOutMode = {
34
- NONE: 0,
35
- SAME_LAYER: 1,
36
- SAME_GROUP: 2,
37
- SAME_LAYER_AND_GROUP: 3,
38
- ALL: 4
39
- };
40
- dragonBones.FadeState = {
41
- FADE_BEFORE: 0,
42
- FADING: 1,
43
- FADE_COMPLETE: 2
44
- };
45
- dragonBones.UpdateState = {
46
- UPDATE: 0,
47
- UPDATE_ONCE: 1,
48
- UNUPDATE: 2
49
- };
50
- dragonBones.EventType = {
51
- Z_ORDER_UPDATED: 0,
52
- ANIMATION_FRAME_EVENT: 1,
53
- BONE_FRAME_EVENT: 2,
54
- SOUND: 3,
55
- FADE_IN: 4,
56
- FADE_OUT: 5,
57
- START: 6,
58
- COMPLETE: 7,
59
- LOOP_COMPLETE: 8,
60
- FADE_IN_COMPLETE: 9,
61
- FADE_OUT_COMPLETE: 10,
62
- _ERROR: 11
63
- };
64
- /*----------------------------------------------------------------------animation部分---------------------------------------------------------------*/
65
- dragonBones.WorldClock = cc.Class.extend({
66
- _dirty: false,
67
- _isPlaying: false,
68
- _time: 0,
69
- _timeScale: 0,
70
- _animatableList: null,
71
- ctor: function (timeScale) {
72
- if (timeScale === undefined)
73
- timeScale = 1;
74
- this._animatableList = [];
75
- this._isPlaying = true;
76
- this._time = 0;
77
- this.setTimeScale(timeScale);
78
- },
79
- getTime: function () {
80
- return this._time;
81
- },
82
- getTimeScale: function () {
83
- return this._timeScale;
84
- },
85
- setTimeScale: function (timeScale) {
86
- if (timeScale < 0 || timeScale != this._timeScale)
87
- timeScale = 1;
88
- this._timeScale = timeScale;
89
- },
90
- dispose: function () {
91
- this._animatableList.length = 0;
92
- },
93
- contains: function (animatable) {
94
- return this._animatableList.indexOf(animatable) >= 0;
95
- },
96
- add: function (animatable) {
97
- if (animatable != null && this._animatableList.indexOf(animatable) == -1) {
98
- this._animatableList.push(animatable);
99
- }
100
- },
101
- remove: function (animatable) {
102
- var index = this._animatableList.indexOf(animatable);
103
- if (index >= 0) {
104
- this._animatableList[index] = null;
105
- this._dirty = true;
106
- }
107
- },
108
- removeAll: function () {
109
- this._animatableList.length = 0;
110
- },
111
- play: function () {
112
- this._isPlaying = true;
113
- },
114
- stop: function () {
115
- this._isPlaying = false;
116
- },
117
- advanceTime: function (passedTime) {
118
- // console.log('advanceTime', passedTime, this._isPlaying)
119
- if (!this._isPlaying) {
120
- return;
121
- }
122
- if (passedTime < 0) {
123
- passedTime = 0;
124
- }
125
- passedTime *= this._timeScale;
126
- this._time += passedTime;
127
- var len = this._animatableList.length;
128
- if (len == 0) {
129
- return;
130
- }
131
- var animatable;
132
- var i;
133
- for (i = 0; i < len; i++) {
134
- animatable = this._animatableList[i];
135
- if (animatable != null) {
136
- animatable.advanceTime(passedTime);
137
- }
138
- }
139
- if (this._dirty) {
140
- var curIdx = 0;
141
- len = this._animatableList.length;
142
- for (i = 0; i < len; i++) {
143
- animatable = this._animatableList[i];
144
- if (animatable != null) {
145
- if (curIdx != i) {
146
- this._animatableList[curIdx] = animatable;
147
- this._animatableList[i] = null;
148
- }
149
- curIdx++;
150
- }
151
- }
152
- this._animatableList.length = curIdx;
153
- this._dirty = false;
154
- }
155
- }
156
- });
157
- dragonBones.WorldClock._instance = null;
158
- dragonBones.WorldClock.getInstance = function () {
159
- if (dragonBones.WorldClock._instance == null) {
160
- dragonBones.WorldClock._instance = new dragonBones.WorldClock();
161
- }
162
- return dragonBones.WorldClock._instance;
163
- };
164
- dragonBones.Animation = cc.Class.extend({
165
- autoTween: false,
166
- _isFading: false,
167
- _isPlaying: false,
168
- _timeScale: 0,
169
- _animationList: null,
170
- _animationDataList: null,
171
- _animationStateList: null,
172
- _armature: null,
173
- _lastAnimationState: null,
174
- ctor: function () {
175
- this.autoTween = true;
176
- this._timeScale = 1;
177
- this._animationList = [];
178
- this._animationDataList = [];
179
- this._animationStateList = [];
180
- },
181
- getIsPlaying: function () {
182
- return this._isPlaying && !this.getIsComplete();
183
- },
184
- getIsComplete: function () {
185
- if (this._lastAnimationState) {
186
- if (!this._lastAnimationState._isComplete) {
187
- return false;
188
- }
189
- var l = this._animationStateList.length;
190
- for (var i = 0; i < l; i++) {
191
- if (!this._animationStateList[i]._isComplete) {
192
- return false;
193
- }
194
- }
195
- return true;
196
- }
197
- return true;
198
- },
199
- getAnimationList: function () {
200
- return this._animationList;
201
- },
202
- getLastAnimationState: function () {
203
- return this._lastAnimationState;
204
- },
205
- getTimeScale: function () {
206
- return this._timeScale;
207
- },
208
- setTimeScale: function (timeScale) {
209
- if (timeScale < 0) {
210
- timeScale = 1;
211
- }
212
- this._timeScale = timeScale;
213
- },
214
- getAnimationDataList: function () {
215
- return this._animationDataList;
216
- },
217
- setAnimationDataList: function (animationDataList) {
218
- this._animationDataList = animationDataList;
219
- this._animationList.length = 0;
220
- var l = this._animationDataList.length;
221
- for (var i = 0; i < l; i++) {
222
- this._animationList.push(this._animationDataList[i].name);
223
- }
224
- },
225
- dispose: function () {
226
- this._animationDataList.length = 0;
227
- var l = this._animationStateList.length;
228
- for (var i = 0; i < l; i++) {
229
- dragonBones.AnimationState.returnObject(this._animationStateList[i]);
230
- }
231
- this._animationStateList.length = 0;
232
- this._armature = null;
233
- this._lastAnimationState = null;
234
- },
235
- clear: function () {
236
- this.stop();
237
- var l = this._animationStateList.length;
238
- var i;
239
- for (i = 0; i < l; i++) {
240
- dragonBones.AnimationState.returnObject(this._animationStateList[i]);
241
- }
242
- this._animationStateList.length = 0;
243
- this._lastAnimationState = null;
244
- l = this._armature._slotList.length;
245
- var childArmature;
246
- for (i = 0; i < l; i++) {
247
- childArmature = this._armature._slotList[i].getChildArmature();
248
- if (childArmature) {
249
- childArmature.getAnimation().clear();
250
- }
251
- }
252
- },
253
- gotoAndPlay: function (animationName, fadeInTime, duration, playTimes, layer, group, fadeOutMode, pauseFadeOut, pauseFadeIn) {
254
- if (fadeInTime === undefined) {
255
- fadeInTime = -1;
256
- }
257
- if (duration === undefined) {
258
- duration = -1;
259
- }
260
- if (playTimes === undefined) {
261
- playTimes = -1;
262
- }
263
- if (layer === undefined) {
264
- layer = 0;
265
- }
266
- if (group === undefined) {
267
- group = null;
268
- }
269
- if (fadeOutMode === undefined) {
270
- fadeOutMode = dragonBones.AnimationFadeOutMode.SAME_LAYER_AND_GROUP;
271
- }
272
- if (pauseFadeOut === undefined) {
273
- pauseFadeOut = true;
274
- }
275
- if (pauseFadeIn === undefined) {
276
- pauseFadeIn = true;
277
- }
278
- if (!this._animationDataList) {
279
- return null;
280
- }
281
- var animationData;
282
- var i = this._animationDataList.length;
283
- while (--i >= 0) {
284
- if (this._animationDataList[i].name == animationName) {
285
- animationData = this._animationDataList[i];
286
- break;
287
- }
288
- }
289
- if (!animationData) {
290
- return null;
291
- }
292
- this._isPlaying = true;
293
- this._isFading = true;
294
- fadeInTime = fadeInTime < 0 ? (animationData.fadeTime < 0 ? 0.3 : animationData.fadeTime) : fadeInTime;
295
- if (fadeInTime <= 0) {
296
- fadeInTime = 0.01;
297
- }
298
- var durationScale;
299
- if (duration < 0) {
300
- durationScale = animationData.scale < 0 ? 1 : animationData.scale;
301
- }
302
- else {
303
- durationScale = duration * 1000 / animationData.duration;
304
- }
305
- if (durationScale == 0) {
306
- durationScale = 0.001;
307
- }
308
- playTimes = playTimes < 0 ? animationData.playTimes : playTimes;
309
- var animationState;
310
- switch (fadeOutMode) {
311
- case dragonBones.AnimationFadeOutMode.NONE:
312
- break;
313
- case dragonBones.AnimationFadeOutMode.SAME_LAYER:
314
- i = this._animationStateList.length;
315
- while (--i >= 0) {
316
- animationState = this._animationStateList[i];
317
- if (animationState._layer == layer) {
318
- animationState.fadeOut(fadeInTime, pauseFadeOut);
319
- }
320
- }
321
- break;
322
- case dragonBones.AnimationFadeOutMode.SAME_GROUP:
323
- i = this._animationStateList.length;
324
- while (--i >= 0) {
325
- animationState = this._animationStateList[i];
326
- if (animationState._group == group) {
327
- animationState.fadeOut(fadeInTime, pauseFadeOut);
328
- }
329
- }
330
- break;
331
- case dragonBones.AnimationFadeOutMode.ALL:
332
- i = this._animationStateList.length;
333
- while (--i >= 0) {
334
- animationState = this._animationStateList[i];
335
- animationState.fadeOut(fadeInTime, pauseFadeOut);
336
- }
337
- break;
338
- case dragonBones.AnimationFadeOutMode.SAME_LAYER_AND_GROUP:
339
- default:
340
- i = this._animationStateList.length;
341
- while (--i >= 0) {
342
- animationState = this._animationStateList[i];
343
- if (animationState._layer == layer && animationState._group == group) {
344
- animationState.fadeOut(fadeInTime, pauseFadeOut);
345
- }
346
- }
347
- break;
348
- }
349
- this._lastAnimationState = dragonBones.AnimationState.borrowObject();
350
- this._lastAnimationState._layer = layer;
351
- this._lastAnimationState._group = group;
352
- this._lastAnimationState.autoTween = this.autoTween;
353
- this._lastAnimationState.fadeIn(this._armature, animationData, fadeInTime, 1 / durationScale, playTimes, pauseFadeIn);
354
- this.addState(this._lastAnimationState);
355
- var slotList = this._armature.getSlots();
356
- var slot;
357
- var childArmature;
358
- i = slotList.length;
359
- while (i--) {
360
- slot = slotList[i];
361
- childArmature = slot.getChildArmature();
362
- if (childArmature && childArmature._isInheritAnimation &&
363
- childArmature._animation.hasAnimation(animationName)) {
364
- childArmature._animation.gotoAndPlay(animationName, fadeInTime);
365
- }
366
- }
367
- return this._lastAnimationState;
368
- },
369
- gotoAndStop: function (animationName, time, normalizedTime, fadeInTime, duration, layer, group, fadeOutMode) {
370
- if (normalizedTime === undefined) {
371
- normalizedTime = -1;
372
- }
373
- if (fadeInTime === undefined) {
374
- fadeInTime = 0;
375
- }
376
- if (duration === undefined) {
377
- duration = -1;
378
- }
379
- if (layer === undefined) {
380
- layer = 0;
381
- }
382
- if (group === undefined) {
383
- group = null;
384
- }
385
- if (fadeOutMode === undefined) {
386
- fadeOutMode = dragonBones.AnimationFadeOutMode.ALL;
387
- }
388
- var animationState = this.getState(animationName, layer);
389
- if (!animationState) {
390
- animationState = this.gotoAndPlay(animationName, fadeInTime, duration, -1, layer, group, fadeOutMode);
391
- }
392
- if (normalizedTime >= 0) {
393
- animationState.setCurrentTime(animationState.getTotalTime() * normalizedTime);
394
- }
395
- else {
396
- animationState.setCurrentTime(time);
397
- }
398
- animationState.stop();
399
- return animationState;
400
- },
401
- play: function () {
402
- if (this._animationDataList.length == 0) {
403
- return;
404
- }
405
- if (!this._lastAnimationState) {
406
- this.gotoAndPlay(this._animationDataList[0].name);
407
- }
408
- else if (!this._isPlaying) {
409
- this._isPlaying = true;
410
- }
411
- },
412
- stop: function () {
413
- this._isPlaying = false;
414
- },
415
- advanceTime: function (passedTime) {
416
- if (!this._isPlaying) {
417
- return;
418
- }
419
- var isFading = false;
420
- passedTime *= this._timeScale;
421
- var animationState;
422
- var l = this._animationStateList.length;
423
- for (var i = 0; i < l; ++i) {
424
- animationState = this._animationStateList[i];
425
- if (animationState.advanceTime(passedTime)) {
426
- this.removeState(animationState);
427
- --i;
428
- --l;
429
- }
430
- else if (animationState._fadeState != dragonBones.FadeState.FADE_COMPLETE) {
431
- isFading = true;
432
- }
433
- }
434
- this._isFading = isFading;
435
- },
436
- hasAnimation: function (animationName) {
437
- var i = this._animationDataList.length;
438
- while (--i >= 0) {
439
- if (this._animationDataList[i].name == animationName) {
440
- return true;
441
- }
442
- }
443
- return false;
444
- },
445
- getState: function (name, layer) {
446
- if (layer === undefined) {
447
- layer = 0;
448
- }
449
- var animationState;
450
- var i = this._animationStateList.length;
451
- while (--i >= 0) {
452
- animationState = this._animationStateList[i];
453
- if (animationState.name == name && animationState._layer == layer) {
454
- return animationState;
455
- }
456
- }
457
- return null;
458
- },
459
- /** @protected */
460
- addState: function (animationState) {
461
- if (this._animationStateList.indexOf(animationState) == -1) {
462
- this._animationStateList.push(animationState);
463
- }
464
- },
465
- /** @protected */
466
- removeState: function (animationState) {
467
- var index = this._animationStateList.indexOf(animationState);
468
- if (index >= 0) {
469
- this._animationStateList.splice(index, 1);
470
- dragonBones.AnimationState.returnObject(animationState);
471
- if (this._lastAnimationState == animationState) {
472
- if (this._animationStateList.length == 0) {
473
- this._lastAnimationState = null;
474
- }
475
- else {
476
- this._lastAnimationState = this._animationStateList[this._animationStateList.length - 1];
477
- }
478
- }
479
- }
480
- },
481
- /** @protected */
482
- updateAnimationStates: function () {
483
- var i = this._animationStateList.length;
484
- while (--i >= 0) {
485
- this._animationStateList[i].updateTimelineStates();
486
- }
487
- }
488
- });
489
- dragonBones.AnimationState = cc.Class.extend({
490
- additiveBlending: false,
491
- autoTween: false,
492
- autoFadeOut: false,
493
- displayControl: false,
494
- lastFrameAutoTween: false,
495
- fadeOutTime: 0,
496
- weight: 0,
497
- name: null,
498
- _isPlaying: false,
499
- _isComplete: false,
500
- _isFadeOut: false,
501
- _pausePlayheadInFade: false,
502
- _currentPlayTimes: 0,
503
- _layer: 0,
504
- _playTimes: 0,
505
- _currentTime: 0,
506
- _currentFrameIndex: 0,
507
- _currentFramePosition: 0,
508
- _currentFrameDuration: 0,
509
- _totalTime: 0,
510
- _time: 0,
511
- _timeScale: 0,
512
- _fadeWeight: 0,
513
- _fadeTotalWeight: 0,
514
- _fadeCurrentTime: 0,
515
- _fadeTotalTime: 0,
516
- _fadeBeginTime: 0,
517
- _group: null,
518
- _fadeState: 0,
519
- _timelineStateList: null,
520
- _mixingTransforms: null,
521
- _clip: null,
522
- _armature: null,
523
- ctor: function () {
524
- this._timelineStateList = [];
525
- this._mixingTransforms = [];
526
- },
527
- getIsComplete: function () {
528
- return this._isComplete;
529
- },
530
- getIsPlaying: function () {
531
- return (this._isPlaying && !this._isComplete);
532
- },
533
- getCurrentPlayTimes: function () {
534
- return this._currentPlayTimes < 0 ? 0 : this._currentPlayTimes;
535
- },
536
- getLayer: function () {
537
- return this._layer;
538
- },
539
- getTotalTime: function () {
540
- return this._totalTime * 0.001; //存在问题
541
- },
542
- getCurrentWeight: function () {
543
- return this._fadeWeight * this.weight;
544
- },
545
- getGroup: function () {
546
- return this._group;
547
- },
548
- getClip: function () {
549
- return this._clip;
550
- },
551
- setAdditiveBlending: function (value) {
552
- this.additiveBlending = value;
553
- return this;
554
- },
555
- setAutoFadeOut: function (value, fadeOutTime_) {
556
- if (fadeOutTime_ === undefined) {
557
- fadeOutTime_ = -1;
558
- }
559
- this.autoFadeOut = value;
560
- if (fadeOutTime_ >= 0) {
561
- this.fadeOutTime = fadeOutTime_;
562
- }
563
- return this;
564
- },
565
- setWeight: function (value) {
566
- this.weight = value;
567
- return this;
568
- },
569
- setFrameTween: function (autoTween_, lastFrameAutoTween_) {
570
- this.autoTween = autoTween_;
571
- this.lastFrameAutoTween = lastFrameAutoTween_;
572
- return this;
573
- },
574
- getPlayTimes: function () {
575
- return this._playTimes;
576
- },
577
- setPlayTimes: function (playTimes) {
578
- this._playTimes = playTimes;
579
- if (Math.round(this._totalTime * 0.001 * this._clip.frameRate) < 2) { //存在问题
580
- this._playTimes = playTimes < 0 ? -1 : 1;
581
- }
582
- else {
583
- this._playTimes = playTimes < 0 ? -playTimes : playTimes;
584
- }
585
- this.autoFadeOut = playTimes < 0 ? true : false;
586
- return this;
587
- },
588
- getCurrentTime: function () {
589
- return this._currentTime < 0 ? 0 : this._currentTime * 0.001;
590
- },
591
- setCurrentTime: function (currentTime) {
592
- if (currentTime < 0 || isNaN(currentTime)) { //存在问题
593
- currentTime = 0;
594
- }
595
- this._time = currentTime;
596
- this._currentTime = this._time * 1000; //这里需要int型
597
- return this;
598
- },
599
- getTimeScale: function () {
600
- return this._timeScale;
601
- },
602
- setTimeScale: function (timeScale) {
603
- if (isNaN(timeScale) || timeScale == Infinity || timeScale === undefined) {
604
- timeScale = 1;
605
- }
606
- this._timeScale = timeScale;
607
- return this;
608
- },
609
- fadeOut: function (fadeTotalTime, pausePlayhead) {
610
- if (!(fadeTotalTime >= 0)) {
611
- fadeTotalTime = 0;
612
- }
613
- this._pausePlayheadInFade = pausePlayhead;
614
- var i;
615
- var len;
616
- if (this._isFadeOut) {
617
- if (fadeTotalTime > this._fadeTotalTime / this._timeScale - (this._fadeCurrentTime - this._fadeBeginTime)) {
618
- //如果已经在淡出中,新的淡出需要更长的淡出时间,则忽略
619
- return this;
620
- }
621
- }
622
- else {
623
- len = this._timelineStateList.length;
624
- i = 0;
625
- while (i < len) {
626
- this._timelineStateList[i].fadeOut();
627
- i++;
628
- }
629
- }
630
- // fade start
631
- this._isFadeOut = true;
632
- this._fadeTotalWeight = this._fadeWeight;
633
- this._fadeState = dragonBones.FadeState.FADE_BEFORE;
634
- this._fadeBeginTime = this._fadeCurrentTime;
635
- this._fadeTotalTime = this._fadeTotalWeight >= 0 ? fadeTotalTime * this._timeScale : 0;
636
- // default
637
- this.displayControl = false;
638
- return this;
639
- },
640
- play: function () {
641
- this._isPlaying = true;
642
- return this;
643
- },
644
- stop: function () {
645
- this._isPlaying = false;
646
- return this;
647
- },
648
- getMixingTransform: function (timelineName) {
649
- return this._mixingTransforms.indexOf(timelineName) >= 0;
650
- },
651
- addMixingTransform: function (timelineName, recursive) {
652
- if (recursive === undefined) {
653
- recursive = true;
654
- }
655
- if (recursive) {
656
- var currentBone = void 0;
657
- var bone = void 0;
658
- var boneName = void 0;
659
- var boneList = this._armature.getBones();
660
- var i = boneList.length;
661
- while (--i >= 0) {
662
- bone = boneList[i];
663
- boneName = bone.name;
664
- if (boneName == timelineName) {
665
- currentBone = bone;
666
- }
667
- if (currentBone && (currentBone == bone || currentBone.contains(bone))) {
668
- if (this._clip.getTimeline(boneName) && this._mixingTransforms.indexOf(boneName) < 0) {
669
- this._mixingTransforms.push(boneName);
670
- }
671
- }
672
- }
673
- }
674
- else if (this._clip.getTimeline(timelineName)) {
675
- if (this._mixingTransforms.indexOf(timelineName) < 0) {
676
- this._mixingTransforms.push(timelineName);
677
- }
678
- }
679
- this.updateTimelineStates();
680
- return this;
681
- },
682
- removeMixingTransform: function (timelineName, recursive) {
683
- if (recursive === undefined) {
684
- recursive = true;
685
- }
686
- var index;
687
- if (recursive) {
688
- var currentBone = void 0;
689
- var bone = void 0;
690
- var boneName;
691
- var boneList = this._armature.getBones();
692
- var i = boneList.length;
693
- while (--i >= 0) {
694
- bone = boneList[i];
695
- boneName = bone.name;
696
- if (boneName == timelineName) {
697
- currentBone = bone;
698
- }
699
- if (currentBone && (currentBone == bone || currentBone.contains(bone))) {
700
- index = this._mixingTransforms.indexOf(boneName);
701
- if (index >= 0) {
702
- this._mixingTransforms.splice(index, 1);
703
- }
704
- }
705
- }
706
- }
707
- else {
708
- index = this._mixingTransforms.indexOf(boneName);
709
- if (index >= 0) {
710
- this._mixingTransforms.splice(index, 1);
711
- }
712
- }
713
- this.updateTimelineStates();
714
- return this;
715
- },
716
- removeAllMixingTransform: function () {
717
- this._mixingTransforms.length = 0;
718
- this.updateTimelineStates();
719
- return this;
720
- },
721
- /** @private */
722
- fadeIn: function (armature, clip, fadeTotalTime, timeScale, playTimes, pausePlayhead) {
723
- this._armature = armature;
724
- this._clip = clip;
725
- this._pausePlayheadInFade = pausePlayhead;
726
- this._totalTime = clip.duration;
727
- this.autoTween = clip.autoTween;
728
- this.name = clip.name;
729
- this.setTimeScale(timeScale);
730
- this.setPlayTimes(playTimes);
731
- // reset
732
- this._isComplete = false;
733
- this._currentFrameIndex = -1;
734
- this._currentPlayTimes = -1;
735
- if (Math.round(this._totalTime * 0.001 * this._clip.frameRate) < 2 || timeScale == Infinity) { //存在问题
736
- this._currentTime = this._totalTime;
737
- }
738
- else {
739
- this._currentTime = -1;
740
- }
741
- this._time = 0;
742
- this._mixingTransforms.length = 0;
743
- // fade start
744
- this._isFadeOut = false;
745
- this._fadeWeight = 0;
746
- this._fadeTotalWeight = 1;
747
- this._fadeCurrentTime = 0;
748
- this._fadeBeginTime = this._fadeCurrentTime;
749
- this._fadeTotalTime = fadeTotalTime * this._timeScale;
750
- this._fadeState = dragonBones.FadeState.FADE_BEFORE;
751
- // default
752
- this._isPlaying = true;
753
- this.displayControl = true;
754
- this.lastFrameAutoTween = true;
755
- this.additiveBlending = false;
756
- this.weight = 1;
757
- this.fadeOutTime = fadeTotalTime;
758
- this.updateTimelineStates();
759
- },
760
- /** @private */
761
- advanceTime: function (passedTime) {
762
- passedTime *= this._timeScale;
763
- this.advanceFadeTime(passedTime);
764
- if (this._fadeWeight) {
765
- this.advanceTimelinesTime(passedTime);
766
- }
767
- return this._isFadeOut && this._fadeState == 2; //dragonBones.FadeState.FADE_COMPLETE
768
- },
769
- /** @private */
770
- updateTimelineStates: function () {
771
- var timelineState;
772
- var i = this._timelineStateList.length;
773
- var len;
774
- while (--i >= 0) {
775
- timelineState = this._timelineStateList[i];
776
- if (!this._armature.getBone(timelineState.name)) {
777
- this.removeTimelineState(timelineState);
778
- }
779
- }
780
- if (this._mixingTransforms.length == 0) {
781
- len = this._clip.timelineList.length;
782
- i = 0;
783
- while (i < len) {
784
- this.addTimelineState(this._clip.timelineList[i].name);
785
- i++;
786
- }
787
- }
788
- else {
789
- i = this._timelineStateList.length;
790
- while (--i >= 0) {
791
- timelineState = this._timelineStateList[i];
792
- if (this._mixingTransforms.indexOf(timelineState.name) < 0) {
793
- this.removeTimelineState(timelineState);
794
- }
795
- }
796
- len = this._mixingTransforms.length;
797
- i = 0;
798
- while (i < len) {
799
- this.addTimelineState(this._mixingTransforms[i]);
800
- i++;
801
- }
802
- }
803
- },
804
- /** @private */
805
- addTimelineState: function (timelineName) {
806
- var bone = this._armature.getBone(timelineName);
807
- if (bone) {
808
- var len = this._timelineStateList.length;
809
- var i = 0;
810
- while (i < len) {
811
- if (this._timelineStateList[i].name == timelineName) {
812
- return;
813
- }
814
- i++;
815
- }
816
- var timelineState = dragonBones.TimelineState.borrowObject();
817
- timelineState.fadeIn(bone, this, this._clip.getTimeline(timelineName));
818
- this._timelineStateList.push(timelineState);
819
- }
820
- },
821
- /** @private */
822
- removeTimelineState: function (timelineState) {
823
- var index = this._timelineStateList.indexOf(timelineState);
824
- if (index >= 0) {
825
- this._timelineStateList.splice(index, 1);
826
- dragonBones.TimelineState.returnObject(timelineState);
827
- }
828
- },
829
- /** @private */
830
- advanceFadeTime: function (passedTime) {
831
- var fadeStartFlg = false;
832
- var fadeCompleteFlg = false;
833
- if (this._fadeBeginTime >= 0) {
834
- var fadeState = this._fadeState;
835
- this._fadeCurrentTime += passedTime < 0 ? -passedTime : passedTime;
836
- if (this._fadeCurrentTime >= this._fadeBeginTime + this._fadeTotalTime) {
837
- // fade complete
838
- if (this._fadeWeight == 1 || this._fadeWeight == 0) {
839
- fadeState = 2; //dragonBones.FadeState.FADE_COMPLETE;
840
- if (this._pausePlayheadInFade) {
841
- this._pausePlayheadInFade = false;
842
- this._currentTime = -1;
843
- }
844
- }
845
- this._fadeWeight = this._isFadeOut ? 0 : 1;
846
- }
847
- else if (this._fadeCurrentTime >= this._fadeBeginTime) {
848
- // fading
849
- fadeState = 1; //dragonBones.FadeState.FADING;
850
- this._fadeWeight = (this._fadeCurrentTime - this._fadeBeginTime) / this._fadeTotalTime * this._fadeTotalWeight;
851
- if (this._isFadeOut) {
852
- this._fadeWeight = this._fadeTotalWeight - this._fadeWeight;
853
- }
854
- }
855
- else {
856
- // fade before
857
- fadeState = 0; //dragonBones.FadeState.FADE_BEFORE;
858
- this._fadeWeight = this._isFadeOut ? 1 : 0;
859
- }
860
- if (this._fadeState != fadeState) {
861
- // _fadeState == FadeState::FADE_BEFORE && (fadeState == FadeState::FADING || fadeState == FadeState::FADE_COMPLETE)
862
- if (this._fadeState == 0) { //dragonBones.FadeState.FADE_BEFORE
863
- fadeStartFlg = true;
864
- }
865
- // (_fadeState == FadeState::FADE_BEFORE || _fadeState == FadeState::FADING) && fadeState == FadeState::FADE_COMPLETE
866
- if (fadeState == 2) { //dragonBones.FadeState.FADE_COMPLETE
867
- fadeCompleteFlg = true;
868
- }
869
- this._fadeState = fadeState;
870
- }
871
- }
872
- var eventDataType;
873
- var eventData;
874
- if (fadeStartFlg) {
875
- if (this._isFadeOut) {
876
- eventDataType = dragonBones.EventType.FADE_OUT;
877
- }
878
- else {
879
- this.hideBones();
880
- eventDataType = dragonBones.EventType.FADE_IN;
881
- }
882
- if (this._armature._eventDispatcher.hasEvent(eventDataType)) {
883
- eventData = dragonBones.EventData.borrowObject(eventDataType);
884
- eventData.armature = this._armature;
885
- eventData.animationState = this;
886
- this._armature._eventDataList.push(eventData);
887
- }
888
- }
889
- if (fadeCompleteFlg) {
890
- if (this._isFadeOut) {
891
- eventDataType = dragonBones.EventType.FADE_OUT_COMPLETE;
892
- }
893
- else {
894
- eventDataType = dragonBones.EventType.FADE_IN_COMPLETE;
895
- }
896
- if (this._armature._eventDispatcher.hasEvent(eventDataType)) {
897
- eventData = dragonBones.EventData.borrowObject(eventDataType);
898
- eventData.armature = this._armature;
899
- eventData.animationState = this;
900
- this._armature._eventDataList.push(eventData);
901
- }
902
- }
903
- },
904
- /** @private */
905
- advanceTimelinesTime: function (passedTime) {
906
- if (this._isPlaying && !this._pausePlayheadInFade) {
907
- this._time += passedTime;
908
- }
909
- var startFlg = false;
910
- var completeFlg = false;
911
- var loopCompleteFlg = false;
912
- var isThisComplete = false;
913
- var currentPlayTimes = 0;
914
- var currentTime = this._time * 1000; //这里需要int型
915
- if (this._playTimes == 0) {
916
- isThisComplete = false;
917
- currentPlayTimes = Math.ceil(Math.abs(currentTime) / this._totalTime); //这里需要int型
918
- currentTime -= Math.floor(currentTime / this._totalTime) * this._totalTime; //这里需要int型
919
- //currentPlayTimes = (int)(ceil(abs(currentTime) / (float)(_totalTime)));
920
- //currentTime -= (int)(floor(currentTime / (float)(_totalTime))) * _totalTime;
921
- if (currentTime < 0) {
922
- currentTime += this._totalTime;
923
- }
924
- }
925
- else {
926
- var totalTimes = this._playTimes * this._totalTime;
927
- if (currentTime >= totalTimes) {
928
- currentTime = totalTimes;
929
- isThisComplete = true;
930
- }
931
- else if (currentTime <= -totalTimes) {
932
- currentTime = -totalTimes;
933
- isThisComplete = true;
934
- }
935
- else {
936
- isThisComplete = false;
937
- }
938
- if (currentTime < 0) {
939
- currentTime += totalTimes;
940
- }
941
- currentPlayTimes = Math.ceil(currentTime / this._totalTime); //这里需要int型
942
- currentTime -= Math.floor(currentTime / this._totalTime) * this._totalTime; //这里需要int型
943
- //currentPlayTimes = (int)(ceil(currentTime / (float)(_totalTime)));
944
- //currentTime -= (int)(floor(currentTime / (float)(_totalTime))) * _totalTime;
945
- if (isThisComplete) {
946
- currentTime = this._totalTime;
947
- }
948
- }
949
- if (currentPlayTimes == 0) {
950
- currentPlayTimes = 1;
951
- }
952
- this._isComplete = isThisComplete;
953
- var progress = this._time * 1000 / this._totalTime; //存在问题
954
- var l = this._timelineStateList.length;
955
- var i = 0;
956
- var timeline;
957
- while (i < l) {
958
- timeline = this._timelineStateList[i];
959
- timeline.update(progress);
960
- this._isComplete = timeline._isComplete && this._isComplete;
961
- i++;
962
- }
963
- // update main timeline
964
- if (this._currentTime != currentTime) {
965
- if (this._currentPlayTimes != currentPlayTimes) { // check loop complete
966
- if (this._currentPlayTimes > 0 && currentPlayTimes > 1) {
967
- loopCompleteFlg = true;
968
- }
969
- this._currentPlayTimes = currentPlayTimes;
970
- }
971
- if (this._currentTime < 0 && !this._pausePlayheadInFade) { // check start
972
- startFlg = true;
973
- }
974
- if (this._isComplete) { // check complete
975
- completeFlg = true;
976
- }
977
- this._currentTime = currentTime;
978
- this.updateMainTimeline(isThisComplete);
979
- }
980
- var eventData;
981
- if (startFlg) {
982
- if (this._armature._eventDispatcher.hasEvent(dragonBones.EventType.START)) {
983
- eventData = dragonBones.EventData.borrowObject(dragonBones.EventType.START);
984
- eventData.armature = this._armature;
985
- eventData.animationState = this;
986
- this._armature._eventDataList.push(eventData);
987
- }
988
- }
989
- if (completeFlg) {
990
- if (this._armature._eventDispatcher.hasEvent(dragonBones.EventType.COMPLETE)) {
991
- eventData = dragonBones.EventData.borrowObject(dragonBones.EventType.COMPLETE);
992
- eventData.armature = this._armature;
993
- eventData.animationState = this;
994
- this._armature._eventDataList.push(eventData);
995
- }
996
- if (this.autoFadeOut) {
997
- this.fadeOut(this.fadeOutTime, true);
998
- }
999
- }
1000
- else if (loopCompleteFlg) {
1001
- if (this._armature._eventDispatcher.hasEvent(dragonBones.EventType.LOOP_COMPLETE)) {
1002
- eventData = dragonBones.EventData.borrowObject(dragonBones.EventType.LOOP_COMPLETE);
1003
- eventData.armature = this._armature;
1004
- eventData.animationState = this;
1005
- this._armature._eventDataList.push(eventData);
1006
- }
1007
- }
1008
- },
1009
- /** @private */
1010
- updateMainTimeline: function (isThisComplete) {
1011
- var frameList = this._clip.frameList;
1012
- var l = frameList.length;
1013
- if (l > 0) {
1014
- var prevFrame = void 0;
1015
- var currentFrame = void 0;
1016
- for (var i = 0; i < l; ++i) {
1017
- if (this._currentFrameIndex < 0) {
1018
- this._currentFrameIndex = 0;
1019
- }
1020
- else if (this._currentTime < this._currentFramePosition || this._currentTime >= this._currentFramePosition + this._currentFrameDuration) {
1021
- ++this._currentFrameIndex;
1022
- if (this._currentFrameIndex >= l) {
1023
- if (isThisComplete) {
1024
- --this._currentFrameIndex;
1025
- break;
1026
- }
1027
- else {
1028
- this._currentFrameIndex = 0;
1029
- }
1030
- }
1031
- }
1032
- else {
1033
- break;
1034
- }
1035
- currentFrame = frameList[this._currentFrameIndex];
1036
- if (prevFrame) {
1037
- this._armature.arriveAtFrame(prevFrame, this, true);
1038
- }
1039
- this._currentFrameDuration = currentFrame.duration;
1040
- this._currentFramePosition = currentFrame.position;
1041
- prevFrame = currentFrame;
1042
- }
1043
- if (currentFrame) {
1044
- this._armature.arriveAtFrame(currentFrame, this, false);
1045
- }
1046
- }
1047
- },
1048
- /** @private */
1049
- hideBones: function () {
1050
- var bone;
1051
- for (var i = 0, l = this._clip.hideTimelineList.length; i < l; i++) {
1052
- bone = this._armature.getBone(this._clip.hideTimelineList[i]);
1053
- if (bone) {
1054
- bone.hideSlots();
1055
- }
1056
- }
1057
- },
1058
- /** @private */
1059
- clear: function () {
1060
- var i = this._timelineStateList.length;
1061
- while (--i >= 0) {
1062
- dragonBones.TimelineState.returnObject(this._timelineStateList[i]);
1063
- }
1064
- this._timelineStateList.length = 0;
1065
- this._mixingTransforms.length = 0;
1066
- this._armature = null;
1067
- this._clip = null;
1068
- }
1069
- });
1070
- var DBAnimationStatePool = [];
1071
- dragonBones.AnimationState._pool = DBAnimationStatePool;
1072
- dragonBones.AnimationState.borrowObject = function () {
1073
- if (DBAnimationStatePool.length == 0) {
1074
- return new dragonBones.AnimationState();
1075
- }
1076
- return DBAnimationStatePool.pop();
1077
- };
1078
- dragonBones.AnimationState.returnObject = function (animationState) {
1079
- var index = DBAnimationStatePool.indexOf(animationState);
1080
- if (index < 0) {
1081
- DBAnimationStatePool.push(animationState);
1082
- }
1083
- animationState.clear();
1084
- };
1085
- dragonBones.AnimationState.clearObjects = function () {
1086
- var i = DBAnimationStatePool.length;
1087
- while (--i >= 0) {
1088
- DBAnimationStatePool[i].clear();
1089
- }
1090
- DBAnimationStatePool.length = 0;
1091
- };
1092
- dragonBones.TimelineState = cc.Class.extend({
1093
- name: null,
1094
- _blendEnabled: false,
1095
- _isComplete: false,
1096
- _tweenTransform: false,
1097
- _tweenScale: false,
1098
- _tweenColor: false,
1099
- _currentTime: 0,
1100
- _currentFrameIndex: 0,
1101
- _currentFramePosition: 0,
1102
- _currentFrameDuration: 0,
1103
- _totalTime: 0,
1104
- _weight: 0,
1105
- _tweenEasing: 0,
1106
- _updateState: 0,
1107
- _transform: null,
1108
- _durationTransform: null,
1109
- _originTransform: null,
1110
- _pivot: null,
1111
- _durationPivot: null,
1112
- _originPivot: null,
1113
- _durationColor: null,
1114
- _bone: null,
1115
- _animationState: null,
1116
- _timeline: null,
1117
- ctor: function () {
1118
- this._transform = new dragonBones.Transform();
1119
- this._durationTransform = new dragonBones.Transform();
1120
- this._pivot = new dragonBones.Point();
1121
- this._durationPivot = new dragonBones.Point();
1122
- this._durationColor = new dragonBones.ColorTransform();
1123
- },
1124
- /** @private */
1125
- fadeIn: function (bone, animationState, timeline) {
1126
- this._bone = bone;
1127
- this._animationState = animationState;
1128
- this._timeline = timeline;
1129
- this._isComplete = false;
1130
- this._blendEnabled = false;
1131
- this._tweenTransform = false;
1132
- this._tweenScale = false;
1133
- this._tweenColor = false;
1134
- this._currentTime = -1;
1135
- this._currentFrameIndex = -1;
1136
- this._weight = 1;
1137
- this._tweenEasing = dragonBones.USE_FRAME_TWEEN_EASING;
1138
- this._totalTime = this._timeline.duration;
1139
- this.name = this._timeline.name;
1140
- this._transform.x = 0;
1141
- this._transform.y = 0;
1142
- this._transform.scaleX = 0;
1143
- this._transform.scaleY = 0;
1144
- this._transform.skewX = 0;
1145
- this._transform.skewY = 0;
1146
- this._pivot.x = 0;
1147
- this._pivot.y = 0;
1148
- this._durationTransform.x = 0;
1149
- this._durationTransform.y = 0;
1150
- this._durationTransform.scaleX = 0;
1151
- this._durationTransform.scaleY = 0;
1152
- this._durationTransform.skewX = 0;
1153
- this._durationTransform.skewY = 0;
1154
- this._durationPivot.x = 0;
1155
- this._durationPivot.y = 0;
1156
- // copy
1157
- this._originTransform = this._timeline.originTransform;
1158
- // copy
1159
- this._originPivot = this._timeline.originPivot;
1160
- switch (this._timeline.frameList.length) {
1161
- case 0:
1162
- this._updateState = 2; //dragonBones.UpdateState.UNUPDATE;
1163
- break;
1164
- case 1:
1165
- this._updateState = 1; //dragonBones.UpdateState.UPDATE_ONCE;
1166
- break;
1167
- default:
1168
- this._updateState = 0; //dragonBones.UpdateState.UPDATE;
1169
- break;
1170
- }
1171
- this._bone.addState(this);
1172
- },
1173
- /** @private */
1174
- fadeOut: function () {
1175
- this._transform.skewX = DBUtils.TransformUtil.formatRadian(this._transform.skewX);
1176
- this._transform.skewY = DBUtils.TransformUtil.formatRadian(this._transform.skewY);
1177
- },
1178
- /** @private */
1179
- update: function (progress) {
1180
- console.log('update timeline', this._parent._needUpdate);
1181
- if (this._updateState == 0) { //UpdateState.UPDATE
1182
- this.updateMultipleFrame(progress);
1183
- }
1184
- else if (this._updateState == 1) { //UpdateState.UPDATE_ONCE
1185
- this.updateSingleFrame();
1186
- this._updateState = 2; //UpdateState.UNUPDATE;
1187
- }
1188
- },
1189
- /** @private */
1190
- updateMultipleFrame: function (progress) {
1191
- progress /= this._timeline.scale;
1192
- progress += this._timeline.offset;
1193
- var currentTime = this._totalTime * progress; //这里需要int型
1194
- var currentPlayTimes = 0;
1195
- var playTimes = this._animationState.getPlayTimes();
1196
- if (playTimes == 0) {
1197
- this._isComplete = false;
1198
- currentPlayTimes = Math.ceil(Math.abs(currentTime) / this._totalTime) || 1; //这里需要int型
1199
- //比对egretDragonBones修改
1200
- if (currentTime >= 0) {
1201
- currentTime -= Math.floor(currentTime / this._totalTime) * this._totalTime; //这里需要int型
1202
- }
1203
- else {
1204
- currentTime -= Math.ceil(currentTime / this._totalTime) * this._totalTime; //这里需要int型
1205
- }
1206
- if (currentTime < 0) {
1207
- currentTime += this._totalTime;
1208
- }
1209
- }
1210
- else {
1211
- var totalTimes = playTimes * this._totalTime;
1212
- if (currentTime >= totalTimes) {
1213
- currentTime = totalTimes;
1214
- this._isComplete = true;
1215
- }
1216
- else if (currentTime <= -totalTimes) {
1217
- currentTime = -totalTimes;
1218
- this._isComplete = true;
1219
- }
1220
- else {
1221
- this._isComplete = false;
1222
- }
1223
- if (currentTime < 0) {
1224
- currentTime += totalTimes;
1225
- }
1226
- currentPlayTimes = Math.ceil(currentTime / this._totalTime) || 1;
1227
- if (this._isComplete) {
1228
- currentTime = this._totalTime;
1229
- }
1230
- else {
1231
- //比对egretDragonBones修改
1232
- if (currentTime >= 0) {
1233
- currentTime -= Math.floor(currentTime / this._totalTime) * this._totalTime;
1234
- }
1235
- else {
1236
- currentTime -= Math.ceil(currentTime / this._totalTime) * this._totalTime;
1237
- }
1238
- }
1239
- }
1240
- if (this._currentTime != currentTime) {
1241
- this._currentTime = currentTime;
1242
- var prevFrame = void 0;
1243
- var currentFrame = void 0;
1244
- var frameList = this._timeline.frameList;
1245
- var l = frameList.length;
1246
- var i = void 0;
1247
- for (i = 0; i < l; ++i) {
1248
- if (this._currentFrameIndex < 0) {
1249
- this._currentFrameIndex = 0;
1250
- }
1251
- else if (this._currentTime < this._currentFramePosition || this._currentTime >= this._currentFramePosition + this._currentFrameDuration) {
1252
- ++this._currentFrameIndex;
1253
- if (this._currentFrameIndex >= l) {
1254
- if (this._isComplete) {
1255
- --this._currentFrameIndex;
1256
- break;
1257
- }
1258
- else {
1259
- this._currentFrameIndex = 0;
1260
- }
1261
- }
1262
- }
1263
- else {
1264
- break;
1265
- }
1266
- currentFrame = frameList[this._currentFrameIndex];
1267
- if (prevFrame) {
1268
- this._bone.arriveAtFrame(prevFrame, this, this._animationState, true);
1269
- }
1270
- this._currentFrameDuration = currentFrame.duration;
1271
- this._currentFramePosition = currentFrame.position;
1272
- prevFrame = currentFrame;
1273
- }
1274
- if (currentFrame) {
1275
- this._bone.arriveAtFrame(currentFrame, this, this._animationState, false);
1276
- this._blendEnabled = currentFrame.displayIndex >= 0;
1277
- if (this._blendEnabled) {
1278
- this.updateToNextFrame(currentPlayTimes);
1279
- }
1280
- else {
1281
- this._tweenEasing = dragonBones.NO_TWEEN_EASING;
1282
- this._tweenTransform = false;
1283
- this._tweenScale = false;
1284
- this._tweenColor = false;
1285
- }
1286
- }
1287
- if (this._blendEnabled) {
1288
- this.updateTween();
1289
- }
1290
- }
1291
- },
1292
- /** @private */
1293
- updateToNextFrame: function (currentPlayTimes) {
1294
- var tweenEnabled = false;
1295
- var nextFrameIndex = this._currentFrameIndex + 1;
1296
- if (nextFrameIndex >= this._timeline.frameList.length) {
1297
- nextFrameIndex = 0;
1298
- }
1299
- var currentFrame = this._timeline.frameList[this._currentFrameIndex];
1300
- var nextFrame = this._timeline.frameList[nextFrameIndex];
1301
- if (nextFrameIndex == 0 &&
1302
- (!this._animationState.lastFrameAutoTween ||
1303
- (this._animationState.getPlayTimes() &&
1304
- this._animationState.getCurrentPlayTimes() >= this._animationState.getPlayTimes() &&
1305
- ((this._currentFramePosition + this._currentFrameDuration) / this._totalTime + currentPlayTimes - this._timeline.offset) * this._timeline.scale > 0.999999))) {
1306
- this._tweenEasing = dragonBones.NO_TWEEN_EASING;
1307
- tweenEnabled = false;
1308
- }
1309
- else if (currentFrame.displayIndex < 0 || nextFrame.displayIndex < 0) {
1310
- this._tweenEasing = dragonBones.NO_TWEEN_EASING;
1311
- tweenEnabled = false;
1312
- }
1313
- else if (this._animationState.autoTween) {
1314
- this._tweenEasing = this._animationState.getClip().tweenEasing;
1315
- if (this._tweenEasing == dragonBones.USE_FRAME_TWEEN_EASING) {
1316
- this._tweenEasing = currentFrame.tweenEasing;
1317
- if (this._tweenEasing == dragonBones.NO_TWEEN_EASING) { // frame no tween
1318
- tweenEnabled = false;
1319
- }
1320
- else {
1321
- if (this._tweenEasing == dragonBones.AUTO_TWEEN_EASING) {
1322
- this._tweenEasing = 0;
1323
- }
1324
- // _tweenEasing [-1, 0) 0 (0, 1] (1, 2]
1325
- tweenEnabled = true;
1326
- }
1327
- }
1328
- else { // animationData overwrite tween
1329
- // _tweenEasing [-1, 0) 0 (0, 1] (1, 2]
1330
- tweenEnabled = true;
1331
- }
1332
- }
1333
- else {
1334
- this._tweenEasing = currentFrame.tweenEasing;
1335
- if (this._tweenEasing == dragonBones.NO_TWEEN_EASING || this._tweenEasing == dragonBones.AUTO_TWEEN_EASING || this._tweenEasing == 0) { // frame no tween
1336
- this._tweenEasing = dragonBones.NO_TWEEN_EASING;
1337
- tweenEnabled = false;
1338
- }
1339
- else {
1340
- // _tweenEasing [-1, 0) 0 (0, 1] (1, 2]
1341
- tweenEnabled = true;
1342
- }
1343
- }
1344
- if (tweenEnabled) {
1345
- // transform
1346
- this._durationTransform.x = nextFrame.transform.x - currentFrame.transform.x;
1347
- this._durationTransform.y = nextFrame.transform.y - currentFrame.transform.y;
1348
- this._durationTransform.skewX = nextFrame.transform.skewX - currentFrame.transform.skewX;
1349
- this._durationTransform.skewY = nextFrame.transform.skewY - currentFrame.transform.skewY;
1350
- this._durationTransform.scaleX = nextFrame.transform.scaleX - currentFrame.transform.scaleX + nextFrame.scaleOffset.x;
1351
- this._durationTransform.scaleY = nextFrame.transform.scaleY - currentFrame.transform.scaleY + nextFrame.scaleOffset.y;
1352
- if (nextFrameIndex == 0) {
1353
- this._durationTransform.skewX = DBUtils.TransformUtil.formatRadian(this._durationTransform.skewX);
1354
- this._durationTransform.skewY = DBUtils.TransformUtil.formatRadian(this._durationTransform.skewY);
1355
- }
1356
- this._durationPivot.x = nextFrame.pivot.x - currentFrame.pivot.x;
1357
- this._durationPivot.y = nextFrame.pivot.y - currentFrame.pivot.y;
1358
- if (this._durationTransform.x ||
1359
- this._durationTransform.y ||
1360
- this._durationTransform.skewX ||
1361
- this._durationTransform.skewY ||
1362
- this._durationTransform.scaleX ||
1363
- this._durationTransform.scaleY ||
1364
- this._durationPivot.x ||
1365
- this._durationPivot.y) {
1366
- this._tweenTransform = true;
1367
- this._tweenScale = currentFrame.tweenScale;
1368
- }
1369
- else {
1370
- this._tweenTransform = false;
1371
- this._tweenScale = false;
1372
- }
1373
- // color
1374
- if (currentFrame.color && nextFrame.color) {
1375
- this._durationColor.alphaOffset = nextFrame.color.alphaOffset - currentFrame.color.alphaOffset;
1376
- this._durationColor.redOffset = nextFrame.color.redOffset - currentFrame.color.redOffset;
1377
- this._durationColor.greenOffset = nextFrame.color.greenOffset - currentFrame.color.greenOffset;
1378
- this._durationColor.blueOffset = nextFrame.color.blueOffset - currentFrame.color.blueOffset;
1379
- this._durationColor.alphaMultiplier = nextFrame.color.alphaMultiplier - currentFrame.color.alphaMultiplier;
1380
- this._durationColor.redMultiplier = nextFrame.color.redMultiplier - currentFrame.color.redMultiplier;
1381
- this._durationColor.greenMultiplier = nextFrame.color.greenMultiplier - currentFrame.color.greenMultiplier;
1382
- this._durationColor.blueMultiplier = nextFrame.color.blueMultiplier - currentFrame.color.blueMultiplier;
1383
- if (this._durationColor.alphaOffset ||
1384
- this._durationColor.redOffset ||
1385
- this._durationColor.greenOffset ||
1386
- this._durationColor.blueOffset ||
1387
- this._durationColor.alphaMultiplier ||
1388
- this._durationColor.redMultiplier ||
1389
- this._durationColor.greenMultiplier ||
1390
- this._durationColor.blueMultiplier) {
1391
- this._tweenColor = true;
1392
- }
1393
- else {
1394
- this._tweenColor = false;
1395
- }
1396
- }
1397
- else if (currentFrame.color) {
1398
- this._tweenColor = true;
1399
- this._durationColor.alphaOffset = -currentFrame.color.alphaOffset;
1400
- this._durationColor.redOffset = -currentFrame.color.redOffset;
1401
- this._durationColor.greenOffset = -currentFrame.color.greenOffset;
1402
- this._durationColor.blueOffset = -currentFrame.color.blueOffset;
1403
- this._durationColor.alphaMultiplier = 1 - currentFrame.color.alphaMultiplier;
1404
- this._durationColor.redMultiplier = 1 - currentFrame.color.redMultiplier;
1405
- this._durationColor.greenMultiplier = 1 - currentFrame.color.greenMultiplier;
1406
- this._durationColor.blueMultiplier = 1 - currentFrame.color.blueMultiplier;
1407
- }
1408
- else if (nextFrame.color) {
1409
- this._tweenColor = true;
1410
- this._durationColor.alphaOffset = nextFrame.color.alphaOffset;
1411
- this._durationColor.redOffset = nextFrame.color.redOffset;
1412
- this._durationColor.greenOffset = nextFrame.color.greenOffset;
1413
- this._durationColor.blueOffset = nextFrame.color.blueOffset;
1414
- this._durationColor.alphaMultiplier = nextFrame.color.alphaMultiplier - 1;
1415
- this._durationColor.redMultiplier = nextFrame.color.redMultiplier - 1;
1416
- this._durationColor.greenMultiplier = nextFrame.color.greenMultiplier - 1;
1417
- this._durationColor.blueMultiplier = nextFrame.color.blueMultiplier - 1;
1418
- }
1419
- else {
1420
- this._tweenColor = false;
1421
- }
1422
- }
1423
- else {
1424
- this._tweenTransform = false;
1425
- this._tweenScale = false;
1426
- this._tweenColor = false;
1427
- }
1428
- if (!this._tweenTransform) {
1429
- if (this._animationState.additiveBlending) {
1430
- this._transform.x = currentFrame.transform.x;
1431
- this._transform.y = currentFrame.transform.y;
1432
- this._transform.skewX = currentFrame.transform.skewX;
1433
- this._transform.skewY = currentFrame.transform.skewY;
1434
- this._transform.scaleX = currentFrame.transform.scaleX;
1435
- this._transform.scaleY = currentFrame.transform.scaleY;
1436
- this._pivot.x = currentFrame.pivot.x;
1437
- this._pivot.y = currentFrame.pivot.y;
1438
- }
1439
- else {
1440
- this._transform.x = this._originTransform.x + currentFrame.transform.x;
1441
- this._transform.y = this._originTransform.y + currentFrame.transform.y;
1442
- this._transform.skewX = this._originTransform.skewX + currentFrame.transform.skewX;
1443
- this._transform.skewY = this._originTransform.skewY + currentFrame.transform.skewY;
1444
- this._transform.scaleX = this._originTransform.scaleX + currentFrame.transform.scaleX;
1445
- this._transform.scaleY = this._originTransform.scaleY + currentFrame.transform.scaleY;
1446
- this._pivot.x = this._originPivot.x + currentFrame.pivot.x;
1447
- this._pivot.y = this._originPivot.y + currentFrame.pivot.y;
1448
- }
1449
- this._bone.invalidUpdate();
1450
- }
1451
- else if (!this._tweenScale) {
1452
- if (this._animationState.additiveBlending) {
1453
- this._transform.scaleX = currentFrame.transform.scaleX;
1454
- this._transform.scaleY = currentFrame.transform.scaleY;
1455
- }
1456
- else {
1457
- this._transform.scaleX = this._originTransform.scaleX + currentFrame.transform.scaleX;
1458
- this._transform.scaleY = this._originTransform.scaleY + currentFrame.transform.scaleY;
1459
- }
1460
- }
1461
- if (!this._tweenColor && this._animationState.displayControl) {
1462
- if (currentFrame.color) {
1463
- this._bone.updateColor(currentFrame.color.alphaOffset, currentFrame.color.redOffset, currentFrame.color.greenOffset, currentFrame.color.blueOffset, currentFrame.color.alphaMultiplier, currentFrame.color.redMultiplier, currentFrame.color.greenMultiplier, currentFrame.color.blueMultiplier, true);
1464
- }
1465
- else if (this._bone._isColorChanged) {
1466
- this._bone.updateColor(0, 0, 0, 0, 1, 1, 1, 1, false);
1467
- }
1468
- }
1469
- },
1470
- /** @private */
1471
- updateTween: function () {
1472
- var progress = (this._currentTime - this._currentFramePosition) / this._currentFrameDuration;
1473
- if (this._tweenEasing && this._tweenEasing != dragonBones.NO_TWEEN_EASING) {
1474
- progress = DBUtils.TransformUtil.getEaseValue(progress, this._tweenEasing);
1475
- }
1476
- var currentFrame = this._timeline.frameList[this._currentFrameIndex];
1477
- if (this._tweenTransform) {
1478
- var currentTransform = currentFrame.transform;
1479
- var currentPivot = currentFrame.pivot;
1480
- if (this._animationState.additiveBlending) {
1481
- //additive blending
1482
- this._transform.x = currentTransform.x + this._durationTransform.x * progress;
1483
- this._transform.y = currentTransform.y + this._durationTransform.y * progress;
1484
- this._transform.skewX = currentTransform.skewX + this._durationTransform.skewX * progress;
1485
- this._transform.skewY = currentTransform.skewY + this._durationTransform.skewY * progress;
1486
- if (this._tweenScale) {
1487
- this._transform.scaleX = currentTransform.scaleX + this._durationTransform.scaleX * progress;
1488
- this._transform.scaleY = currentTransform.scaleY + this._durationTransform.scaleY * progress;
1489
- }
1490
- this._pivot.x = currentPivot.x + this._durationPivot.x * progress;
1491
- this._pivot.y = currentPivot.y + this._durationPivot.y * progress;
1492
- }
1493
- else {
1494
- // normal blending
1495
- this._transform.x = this._originTransform.x + currentTransform.x + this._durationTransform.x * progress;
1496
- this._transform.y = this._originTransform.y + currentTransform.y + this._durationTransform.y * progress;
1497
- this._transform.skewX = this._originTransform.skewX + currentTransform.skewX + this._durationTransform.skewX * progress;
1498
- this._transform.skewY = this._originTransform.skewY + currentTransform.skewY + this._durationTransform.skewY * progress;
1499
- if (this._tweenScale) {
1500
- this._transform.scaleX = this._originTransform.scaleX + currentTransform.scaleX + this._durationTransform.scaleX * progress;
1501
- this._transform.scaleY = this._originTransform.scaleY + currentTransform.scaleY + this._durationTransform.scaleY * progress;
1502
- }
1503
- this._pivot.x = this._originPivot.x + currentPivot.x + this._durationPivot.x * progress;
1504
- this._pivot.y = this._originPivot.y + currentPivot.y + this._durationPivot.y * progress;
1505
- }
1506
- this._bone.invalidUpdate();
1507
- }
1508
- if (this._tweenColor && this._animationState.displayControl) {
1509
- if (currentFrame.color) {
1510
- this._bone.updateColor(currentFrame.color.alphaOffset + this._durationColor.alphaOffset * progress, currentFrame.color.redOffset + this._durationColor.redOffset * progress, currentFrame.color.greenOffset + this._durationColor.greenOffset * progress, currentFrame.color.blueOffset + this._durationColor.blueOffset * progress, currentFrame.color.alphaMultiplier + this._durationColor.alphaMultiplier * progress, currentFrame.color.redMultiplier + this._durationColor.redMultiplier * progress, currentFrame.color.greenMultiplier + this._durationColor.greenMultiplier * progress, currentFrame.color.blueMultiplier + this._durationColor.blueMultiplier * progress, true);
1511
- }
1512
- else {
1513
- this._bone.updateColor(this._durationColor.alphaOffset * progress, this._durationColor.redOffset * progress, this._durationColor.greenOffset * progress, this._durationColor.blueOffset * progress, 1 + this._durationColor.alphaMultiplier * progress, 1 + this._durationColor.redMultiplier * progress, 1 + this._durationColor.greenMultiplier * progress, 1 + this._durationColor.blueMultiplier * progress, true);
1514
- }
1515
- }
1516
- },
1517
- /** @private */
1518
- updateSingleFrame: function () {
1519
- var currentFrame = this._timeline.frameList[0];
1520
- this._bone.arriveAtFrame(currentFrame, this, this._animationState, false);
1521
- this._isComplete = true;
1522
- this._tweenTransform = false;
1523
- this._tweenScale = false;
1524
- this._tweenColor = false;
1525
- this._tweenEasing = dragonBones.NO_TWEEN_EASING;
1526
- this._blendEnabled = currentFrame.displayIndex >= 0;
1527
- if (this._blendEnabled) {
1528
- if (this._animationState.additiveBlending) {
1529
- // additive blending
1530
- // singleFrame.transform (0)
1531
- this._transform.x =
1532
- this._transform.y =
1533
- this._transform.skewX =
1534
- this._transform.skewY =
1535
- this._transform.scaleX =
1536
- this._transform.scaleY = 0;
1537
- this._pivot.x = 0;
1538
- this._pivot.y = 0;
1539
- }
1540
- else {
1541
- this._transform.x = this._originTransform.x;
1542
- this._transform.y = this._originTransform.y;
1543
- this._transform.skewX = this._originTransform.skewX;
1544
- this._transform.skewY = this._originTransform.skewY;
1545
- this._transform.scaleX = this._originTransform.scaleX;
1546
- this._transform.scaleY = this._originTransform.scaleY;
1547
- this._pivot.x = this._originPivot.x;
1548
- this._pivot.y = this._originPivot.y;
1549
- }
1550
- this._bone.invalidUpdate();
1551
- if (this._animationState.displayControl) {
1552
- if (currentFrame.color) {
1553
- this._bone.updateColor(currentFrame.color.alphaOffset, currentFrame.color.redOffset, currentFrame.color.greenOffset, currentFrame.color.blueOffset, currentFrame.color.alphaMultiplier, currentFrame.color.redMultiplier, currentFrame.color.greenMultiplier, currentFrame.color.blueMultiplier, true);
1554
- }
1555
- else if (this._bone._isColorChanged) {
1556
- this._bone.updateColor(0, 0, 0, 0, 1, 1, 1, 1, false);
1557
- }
1558
- }
1559
- }
1560
- },
1561
- /** @private */
1562
- clear: function () {
1563
- if (this._bone) {
1564
- this._bone.removeState(this);
1565
- this._bone = null;
1566
- }
1567
- this._animationState = null;
1568
- this._timeline = null;
1569
- this._originTransform = null;
1570
- this._originPivot = null;
1571
- }
1572
- });
1573
- var DBTimelineStatePool = [];
1574
- dragonBones.TimelineState._pool = DBTimelineStatePool;
1575
- dragonBones.TimelineState.borrowObject = function () {
1576
- if (DBTimelineStatePool.length == 0) {
1577
- return new dragonBones.TimelineState();
1578
- }
1579
- return DBTimelineStatePool.pop();
1580
- };
1581
- dragonBones.TimelineState.returnObject = function (timelineState) {
1582
- if (DBTimelineStatePool.indexOf(timelineState) < 0) {
1583
- DBTimelineStatePool.push(timelineState);
1584
- }
1585
- timelineState.clear();
1586
- };
1587
- dragonBones.TimelineState.clearObjects = function () {
1588
- var i = DBTimelineStatePool.length;
1589
- while (--i >= 0) {
1590
- DBTimelineStatePool[i].clear();
1591
- }
1592
- DBTimelineStatePool.length = 0;
1593
- };
1594
- /*----------------------------------------------------------------------animation部分---------------------------------------------------------------*/
1595
- /*----------------------------------------------------------------------core部分---------------------------------------------------------------*/
1596
- dragonBones.Armature = cc.Class.extend({
1597
- name: null,
1598
- userData: null,
1599
- _needUpdate: false,
1600
- _slotsZOrderChanged: false,
1601
- _delayDispose: false,
1602
- _lockDispose: false,
1603
- _isInheritAnimation: false,
1604
- _boneList: null,
1605
- _slotList: null,
1606
- _eventDataList: null,
1607
- _armatureData: null,
1608
- _animation: null,
1609
- _eventDispatcher: null,
1610
- _display: null,
1611
- _displayBatchNode: null,
1612
- ctor: function (armatureData, animation, eventDispatcher, display) {
1613
- this._armatureData = armatureData;
1614
- this._animation = animation;
1615
- this._eventDispatcher = eventDispatcher;
1616
- this._display = display;
1617
- this._animation._armature = this;
1618
- this._slotsZOrderChanged = false;
1619
- this._boneList = [];
1620
- this._slotList = [];
1621
- this._eventDataList = [];
1622
- this._delayDispose = false;
1623
- this._lockDispose = false;
1624
- this._needUpdate = false;
1625
- this._isInheritAnimation = true;
1626
- },
1627
- getBoundingBox: function () { },
1628
- getBones: function () {
1629
- return this._boneList;
1630
- },
1631
- getSlots: function () {
1632
- return this._slotList;
1633
- },
1634
- getArmatureData: function () {
1635
- return this._armatureData;
1636
- },
1637
- getAnimation: function () {
1638
- return this._animation;
1639
- },
1640
- getDisplay: function () {
1641
- return this._display;
1642
- },
1643
- getEventDispatcher: function () {
1644
- return this._eventDispatcher;
1645
- },
1646
- isInheritAnimation: function () { return this._isInheritAnimation; },
1647
- setInheritAnimation: function (b) { this._isInheritAnimation = b; },
1648
- getBone: function (boneName) {
1649
- var len = this._boneList.length;
1650
- var bone;
1651
- for (var i = 0; i < len; ++i) {
1652
- bone = this._boneList[i];
1653
- if (bone.name == boneName) {
1654
- return bone;
1655
- }
1656
- }
1657
- return null;
1658
- },
1659
- getBoneByDisplay: function (display) {
1660
- var slot = this.getSlotByDisplay(display);
1661
- return slot ? slot._parent : null;
1662
- },
1663
- addBone: function (bone, parentBoneName) {
1664
- if (parentBoneName === undefined) {
1665
- if (bone._parent) {
1666
- bone._parent.removeChild(bone);
1667
- }
1668
- bone.setArmature(this);
1669
- }
1670
- else {
1671
- if (parentBoneName == null) {
1672
- throw new Error();
1673
- }
1674
- var boneParent = this.getBone(parentBoneName);
1675
- if (!boneParent)
1676
- throw new Error();
1677
- boneParent.addChild(bone);
1678
- }
1679
- },
1680
- removeBone: function (bone) {
1681
- if (bone == null)
1682
- throw new Error();
1683
- if (cc.isString(bone)) {
1684
- var bone1 = this.getBone(bone);
1685
- if (bone1) {
1686
- this.removeBone(bone1);
1687
- }
1688
- return bone1;
1689
- }
1690
- else {
1691
- if (bone._armature != this)
1692
- throw new Error();
1693
- if (bone._parent) {
1694
- bone._parent.removeChild(bone);
1695
- }
1696
- else {
1697
- bone.setArmature(null);
1698
- }
1699
- }
1700
- },
1701
- removeBoneByName: function (boneName) {
1702
- var bone = this.getBone(boneName);
1703
- if (bone) {
1704
- this.removeBone(bone);
1705
- }
1706
- return bone;
1707
- },
1708
- getSlot: function (slotName) {
1709
- var len = this._slotList.length;
1710
- var slot;
1711
- for (var i = 0; i < len; ++i) {
1712
- slot = this._slotList[i];
1713
- if (slot.name == slotName) {
1714
- return slot;
1715
- }
1716
- }
1717
- return null;
1718
- },
1719
- getSlotByDisplay: function (display) {
1720
- if (display) {
1721
- var len = this._slotList.length;
1722
- var slot = void 0;
1723
- for (var i = 0; i < len; ++i) {
1724
- slot = this._slotList[i];
1725
- if (slot._display == display) {
1726
- return slot;
1727
- }
1728
- }
1729
- }
1730
- return null;
1731
- },
1732
- addSlot: function (slot, parentBoneName) {
1733
- var bone = this.getBone(parentBoneName);
1734
- if (bone) {
1735
- bone.addChild(slot);
1736
- }
1737
- else {
1738
- throw new Error(); //抛出错误
1739
- }
1740
- },
1741
- removeSlot: function (slot) {
1742
- if (!slot || slot._armature != this) {
1743
- throw new Error(); //抛出错误
1744
- }
1745
- slot._parent.removeChild(slot);
1746
- },
1747
- removeSlotByName: function (slotName) {
1748
- var slot = this.getSlot(slotName);
1749
- if (slot) {
1750
- this.removeSlot(slot);
1751
- }
1752
- return slot;
1753
- },
1754
- replaceSlot: function (boneName, oldSlotName, newSlot) {
1755
- var bone = this.getBone(boneName);
1756
- if (!bone)
1757
- return;
1758
- var slots = bone.getSlots();
1759
- var len = slots.length;
1760
- var i;
1761
- var it;
1762
- var oldSlog;
1763
- for (i = 0; i < len; i++) {
1764
- it = slots[i];
1765
- if (it.name == oldSlotName) {
1766
- oldSlog = it;
1767
- break;
1768
- }
1769
- }
1770
- if (oldSlog) {
1771
- newSlot._tweenZOrder = oldSlog._tweenZOrder;
1772
- newSlot._originZOrder = oldSlog._originZOrder;
1773
- newSlot._offsetZOrder = oldSlog._offsetZOrder;
1774
- newSlot._blendMode = oldSlog._blendMode;
1775
- this.removeSlot(oldSlog);
1776
- }
1777
- newSlot.name = oldSlotName;
1778
- bone.addChild(newSlot);
1779
- },
1780
- sortSlotsByZOrder: function () {
1781
- this._slotList.sort(this.sortSlot);
1782
- var l = this._slotList.length;
1783
- var i;
1784
- var slot;
1785
- for (i = 0; i < l; ++i) {
1786
- slot = this._slotList[i];
1787
- if (slot._isShowDisplay) {
1788
- slot.removeDisplayFromContainer();
1789
- }
1790
- }
1791
- l = this._slotList.length;
1792
- for (i = 0; i < l; ++i) {
1793
- slot = this._slotList[i];
1794
- if (slot._isShowDisplay) {
1795
- slot.addDisplayToContainer(this, -1);
1796
- }
1797
- }
1798
- this._slotsZOrderChanged = false;
1799
- },
1800
- invalidUpdate: function (boneName) {
1801
- if (boneName === undefined) {
1802
- boneName = null;
1803
- }
1804
- if (boneName) {
1805
- if (boneName == null)
1806
- throw Error();
1807
- var bone = this.getBone(boneName);
1808
- if (bone) {
1809
- bone.invalidUpdate();
1810
- }
1811
- }
1812
- else {
1813
- var i = this._boneList.length;
1814
- while (--i >= 0) {
1815
- this._boneList[i].invalidUpdate();
1816
- }
1817
- }
1818
- },
1819
- advanceTime: function (passedTime) {
1820
- this._lockDispose = true;
1821
- this._animation.advanceTime(passedTime);
1822
- passedTime *= this._animation._timeScale;
1823
- var isFading = this._animation._isFading;
1824
- var i = this._boneList.length;
1825
- while (--i >= 0) {
1826
- this._boneList[i].update(isFading);
1827
- }
1828
- i = this._slotList.length;
1829
- var slot;
1830
- while (--i >= 0) {
1831
- slot = this._slotList[i];
1832
- slot.update();
1833
- if (slot._isShowDisplay && slot._childArmature) {
1834
- slot._childArmature.advanceTime(passedTime);
1835
- }
1836
- }
1837
- if (this._slotsZOrderChanged) {
1838
- this.sortSlotsByZOrder();
1839
- //不发送更新Z轴事件
1840
- /*if (this._eventDispatcher.hasEvent(dragonBones.EventType.Z_ORDER_UPDATED)){
1841
- var eventData = new dragonBones.EventData(dragonBones.EventType.Z_ORDER_UPDATED, this);
1842
- this._eventDataList.push(eventData);
1843
- }*/
1844
- }
1845
- var len = this._eventDataList.length;
1846
- var event;
1847
- if (len > 0) {
1848
- for (i = 0; i < len; ++i) {
1849
- event = this._eventDataList[i];
1850
- this._eventDispatcher.dispatchEvent(event);
1851
- dragonBones.EventData.returnObject(event);
1852
- }
1853
- this._eventDataList.length = 0;
1854
- }
1855
- this._lockDispose = false;
1856
- if (this._delayDispose) {
1857
- this.dispose();
1858
- }
1859
- },
1860
- dispose: function () {
1861
- this._delayDispose = true;
1862
- if (!this._animation || this._lockDispose) {
1863
- return;
1864
- }
1865
- if (this._animation) {
1866
- this._animation.dispose();
1867
- this._animation = null;
1868
- }
1869
- //存在问题
1870
- var i = this._boneList.length;
1871
- while (--i >= 0) {
1872
- this._boneList[i].dispose();
1873
- }
1874
- i = this._slotList.length;
1875
- while (--i >= 0) {
1876
- this._slotList[i].dispose();
1877
- }
1878
- i = this._eventDataList.length;
1879
- while (--i >= 0) {
1880
- dragonBones.EventData.returnObject(this._eventDataList[i]);
1881
- }
1882
- this._boneList.length = 0;
1883
- this._slotList.length = 0;
1884
- this._eventDataList.length = 0;
1885
- if (this._eventDispatcher) {
1886
- this._eventDispatcher.dispose();
1887
- this._eventDispatcher = null;
1888
- }
1889
- if (this._display)
1890
- this._display = null;
1891
- if (this.userData)
1892
- this.userData = null;
1893
- },
1894
- /** @protected */
1895
- addObject: function (object) {
1896
- if (object instanceof dragonBones.Bone) {
1897
- if (this._boneList.indexOf(object) < 0) {
1898
- this._boneList.push(object);
1899
- this.sortBones();
1900
- this._animation.updateAnimationStates();
1901
- }
1902
- }
1903
- else if (object instanceof dragonBones.Slot) {
1904
- if (this._slotList.indexOf(object) < 0) {
1905
- this._slotList.push(object);
1906
- }
1907
- }
1908
- },
1909
- /** @protected */
1910
- removeObject: function (object) {
1911
- var index;
1912
- if (object instanceof dragonBones.Bone) {
1913
- index = this._boneList.indexOf(object);
1914
- if (index >= 0) {
1915
- this._boneList.splice(index, 1);
1916
- this._animation.updateAnimationStates();
1917
- }
1918
- }
1919
- else if (object instanceof dragonBones.Slot) {
1920
- index = this._slotList.indexOf(object);
1921
- if (index >= 0) {
1922
- this._slotList.splice(index, 1);
1923
- }
1924
- }
1925
- },
1926
- /** @protected */
1927
- sortBones: function () {
1928
- var l = this._boneList.length;
1929
- if (l == 0) {
1930
- return;
1931
- }
1932
- var sortedList = [];
1933
- var i;
1934
- var bone;
1935
- var parentBone;
1936
- var level;
1937
- for (i = 0; i < l; ++i) {
1938
- bone = this._boneList[i];
1939
- parentBone = bone;
1940
- level = 0;
1941
- while (parentBone) {
1942
- parentBone = parentBone._parent;
1943
- ++level;
1944
- }
1945
- sortedList.push([level, bone]);
1946
- }
1947
- sortedList.sort(dragonBones.Armature.sortBone);
1948
- l = sortedList.length;
1949
- for (i = 0; i < l; ++i) {
1950
- this._boneList[i] = sortedList[i][1];
1951
- }
1952
- },
1953
- /** @protected */
1954
- sortSlot: function (a, b) {
1955
- return a.getZOrder() - b.getZOrder();
1956
- },
1957
- /** @protected */
1958
- arriveAtFrame: function (frame, animationState, isCross) {
1959
- var eventData;
1960
- if (frame.event && this._eventDispatcher.hasEvent(dragonBones.EventType.ANIMATION_FRAME_EVENT)) {
1961
- eventData = dragonBones.EventData.borrowObject(dragonBones.EventType.ANIMATION_FRAME_EVENT);
1962
- eventData.armature = this;
1963
- eventData.animationState = animationState;
1964
- eventData.frameLabel = frame.event;
1965
- eventData.frame = frame;
1966
- this._eventDataList.push(eventData);
1967
- }
1968
- if (frame.sound && DBSoundEventDispatcher && DBSoundEventDispatcher.hasEvent(dragonBones.EventType.SOUND)) {
1969
- eventData = dragonBones.EventData.borrowObject(dragonBones.EventType.SOUND);
1970
- eventData.armature = this;
1971
- eventData.animationState = animationState;
1972
- eventData.sound = frame.sound;
1973
- DBSoundEventDispatcher.dispatchEvent(eventData);
1974
- }
1975
- if (frame.action) {
1976
- if (animationState.displayControl) {
1977
- this._animation.gotoAndPlay(frame.action);
1978
- }
1979
- }
1980
- }
1981
- });
1982
- var DBSoundEventDispatcher = null; //替换dragonBones.Armature.soundEventDispatcher = null;
1983
- dragonBones.Armature.sortBone = function (a, b) {
1984
- return a[0] > b[0] ? -1 : 1;
1985
- };
1986
- dragonBones.Object = cc.Class.extend({
1987
- inheritRotation: false,
1988
- inheritScale: false,
1989
- name: null,
1990
- global: null,
1991
- origin: null,
1992
- offset: null,
1993
- globalTransformMatrix: null,
1994
- userData: null,
1995
- _visible: false,
1996
- _armature: null,
1997
- _parent: null,
1998
- ctor: function () {
1999
- this.global = new dragonBones.Transform();
2000
- this.origin = new dragonBones.Transform();
2001
- this.offset = new dragonBones.Transform();
2002
- this.offset.scaleX = 1;
2003
- this.offset.scaleY = 1;
2004
- this.globalTransformMatrix = new dragonBones.Matrix();
2005
- this._visible = true;
2006
- },
2007
- getVisible: function () {
2008
- return this._visible;
2009
- },
2010
- setVisible: function (value) {
2011
- this._visible = value;
2012
- },
2013
- getParent: function () {
2014
- return this._parent;
2015
- },
2016
- getArmature: function () {
2017
- return this._armature;
2018
- },
2019
- /** @protected */
2020
- setParent: function (value) {
2021
- this._parent = value;
2022
- },
2023
- /** @protected */
2024
- setArmature: function (value) {
2025
- if (this._armature) {
2026
- this._armature.removeObject(this);
2027
- }
2028
- this._armature = value;
2029
- if (this._armature) {
2030
- this._armature.addObject(this);
2031
- }
2032
- },
2033
- dispose: function () {
2034
- this._parent = null;
2035
- this._armature = null;
2036
- this._globalTransformMatrix = null;
2037
- this.global = null;
2038
- this.origin = null;
2039
- this.offset = null;
2040
- this.userData = null;
2041
- }
2042
- });
2043
- dragonBones.Bone = dragonBones.Object.extend({
2044
- displayController: null,
2045
- _isColorChanged: false,
2046
- _needUpdate: 0,
2047
- _tweenPivot: null,
2048
- _tween: null,
2049
- _boneList: null,
2050
- _slotList: null,
2051
- _timelineStateList: null,
2052
- ctor: function () {
2053
- dragonBones.Object.prototype.ctor.call(this);
2054
- this._needUpdate = 2;
2055
- this._tween = new dragonBones.Transform();
2056
- this._tween.scaleX = 0;
2057
- this._tween.scaleY = 0;
2058
- this._tweenPivot = new dragonBones.Point();
2059
- this._boneList = [];
2060
- this._slotList = [];
2061
- this._timelineStateList = [];
2062
- this.inheritRotation = true;
2063
- this.inheritScale = false;
2064
- },
2065
- getSlot: function () {
2066
- return this._slotList.length == 0 ? null : this._slotList[0];
2067
- },
2068
- getSlots: function () {
2069
- return this._slotList;
2070
- },
2071
- getBones: function () {
2072
- return this._boneList;
2073
- },
2074
- setVisible: function (visible) {
2075
- if (this._visible != visible) {
2076
- this._visible = visible;
2077
- var l = this._slotList.length;
2078
- for (var i = 0; i < l; ++i) {
2079
- this._slotList[i].updateDisplayVisible(this._visible);
2080
- }
2081
- }
2082
- },
2083
- dispose: function () {
2084
- if (!this._boneList) {
2085
- return;
2086
- }
2087
- dragonBones.Object.prototype.dispose.call(this);
2088
- var i = this._boneList.length;
2089
- while (--i >= 0) {
2090
- this._boneList[i].dispose();
2091
- }
2092
- i = this._slotList.length;
2093
- while (--i >= 0) {
2094
- this._slotList[i].dispose();
2095
- }
2096
- this._timelineStateList.length = 0;
2097
- this._tween = null;
2098
- this._tweenPivot = null;
2099
- this._boneList = null;
2100
- this._slotList = null;
2101
- this._timelineStateList = null;
2102
- },
2103
- invalidUpdate: function () {
2104
- this._needUpdate = 2;
2105
- },
2106
- contains: function (object) {
2107
- if (!object) {
2108
- throw new Error();
2109
- }
2110
- if (object == this) {
2111
- return false;
2112
- }
2113
- var ancestor = object;
2114
- while (!(ancestor == this || ancestor == null)) {
2115
- ancestor = ancestor.getParent();
2116
- }
2117
- return ancestor == this;
2118
- },
2119
- addChild: function (object) {
2120
- if (!object) {
2121
- throw new Error();
2122
- }
2123
- var bone = (object instanceof dragonBones.Bone) ? object : null;
2124
- var slot = (object instanceof dragonBones.Slot) ? object : null;
2125
- if (object == this || (bone && bone.contains(this))) {
2126
- cc.assert(true, 'Error An Bone cannot be added as a child to itself or one of its children (or children\'s children, etc.)');
2127
- }
2128
- if (object && object.getParent()) {
2129
- object.getParent().removeChild(object);
2130
- }
2131
- if (bone) {
2132
- this._boneList.push(bone);
2133
- bone.setParent(this);
2134
- bone.setArmature(this._armature);
2135
- }
2136
- else if (slot) {
2137
- this._slotList.push(slot);
2138
- slot.setParent(this);
2139
- slot.setArmature(this._armature);
2140
- }
2141
- },
2142
- removeChild: function (object) {
2143
- if (!object) {
2144
- throw new Error();
2145
- }
2146
- var bone = (object instanceof dragonBones.Bone) ? object : null;
2147
- var slot = (object instanceof dragonBones.Slot) ? object : null;
2148
- var index;
2149
- if (bone) {
2150
- index = this._boneList.indexOf(bone);
2151
- if (index < 0) {
2152
- throw new Error();
2153
- }
2154
- this._boneList.splice(index, 1);
2155
- bone.setParent(null);
2156
- bone.setArmature(null);
2157
- }
2158
- else if (slot) {
2159
- index = this._slotList.indexOf(slot);
2160
- if (index < 0) {
2161
- throw new Error();
2162
- }
2163
- this._slotList.splice(index, 1);
2164
- slot.setParent(null);
2165
- slot.setArmature(null);
2166
- }
2167
- },
2168
- /** @protected */
2169
- setArmature: function (armature) {
2170
- dragonBones.Object.prototype.setArmature.call(this, armature);
2171
- var i;
2172
- var l = this._boneList.length;
2173
- for (i = 0; i < l; ++i) {
2174
- this._boneList[i].setArmature(armature);
2175
- }
2176
- l = this._slotList.length;
2177
- for (i = 0; i < l; ++i) {
2178
- this._slotList[i].setArmature(armature);
2179
- }
2180
- },
2181
- /** @protected */
2182
- update: function (needUpdate) {
2183
- // console.log('update bone', needUpdate)
2184
- this._needUpdate--;
2185
- if (needUpdate || this._needUpdate > 0 || (this._parent && this._parent._needUpdate > 0)) {
2186
- this._needUpdate = 1;
2187
- }
2188
- else {
2189
- return;
2190
- }
2191
- this.blendingTimeline();
2192
- this.global.scaleX = (this.origin.scaleX + this._tween.scaleX) * this.offset.scaleX;
2193
- this.global.scaleY = (this.origin.scaleY + this._tween.scaleY) * this.offset.scaleY;
2194
- if (this._parent) {
2195
- var x = this.origin.x + this.offset.x + this._tween.x;
2196
- var y = this.origin.y + this.offset.y + this._tween.y;
2197
- var parentMatrix = this._parent.globalTransformMatrix;
2198
- this.globalTransformMatrix.tx = this.global.x = parentMatrix.a * x + parentMatrix.c * y + parentMatrix.tx;
2199
- this.globalTransformMatrix.ty = this.global.y = parentMatrix.d * y + parentMatrix.b * x + parentMatrix.ty;
2200
- if (this.inheritRotation) {
2201
- this.global.skewX = this.origin.skewX + this.offset.skewX + this._tween.skewX + this._parent.global.skewX;
2202
- this.global.skewY = this.origin.skewY + this.offset.skewY + this._tween.skewY + this._parent.global.skewY;
2203
- }
2204
- else {
2205
- this.global.skewX = this.origin.skewX + this.offset.skewX + this._tween.skewX;
2206
- this.global.skewY = this.origin.skewY + this.offset.skewY + this._tween.skewY;
2207
- }
2208
- if (this.inheritScale) {
2209
- this.global.scaleX *= this._parent.global.scaleX;
2210
- this.global.scaleY *= this._parent.global.scaleY;
2211
- }
2212
- }
2213
- else {
2214
- this.globalTransformMatrix.tx = this.global.x = this.origin.x + this.offset.x + this._tween.x;
2215
- this.globalTransformMatrix.ty = this.global.y = this.origin.y + this.offset.y + this._tween.y;
2216
- this.global.skewX = this.origin.skewX + this.offset.skewX + this._tween.skewX;
2217
- this.global.skewY = this.origin.skewY + this.offset.skewY + this._tween.skewY;
2218
- }
2219
- this.globalTransformMatrix.a = this.global.scaleX * Math.cos(this.global.skewY);
2220
- this.globalTransformMatrix.b = this.global.scaleX * Math.sin(this.global.skewY);
2221
- this.globalTransformMatrix.c = -this.global.scaleY * Math.sin(this.global.skewX);
2222
- this.globalTransformMatrix.d = this.global.scaleY * Math.cos(this.global.skewX);
2223
- },
2224
- /** @protected */
2225
- updateColor: function (aOffset, rOffset, gOffset, bOffset, aMultiplier, rMultiplier, gMultiplier, bMultiplier, colorChanged) {
2226
- var l = this._slotList.length;
2227
- for (var i = 0; i < l; ++i) {
2228
- this._slotList[i].updateDisplayColor(aOffset, rOffset, gOffset, bOffset, aMultiplier, rMultiplier, gMultiplier, bMultiplier);
2229
- }
2230
- this._isColorChanged = colorChanged;
2231
- },
2232
- /** @protected */
2233
- hideSlots: function () {
2234
- var l = this._slotList.length;
2235
- for (var i = 0; i < l; ++i) {
2236
- this._slotList[i].changeDisplay(-1);
2237
- }
2238
- },
2239
- /** @protected */
2240
- arriveAtFrame: function (frame, timelineState, animationState, isCross) {
2241
- var displayControl = animationState.displayControl && (!this.displayController || this.displayController == animationState.name);
2242
- var l;
2243
- var i;
2244
- var slot;
2245
- if (displayControl) {
2246
- var displayIndex = frame.displayIndex;
2247
- l = this._slotList.length;
2248
- for (i = 0; i < l; ++i) {
2249
- slot = this._slotList[i];
2250
- slot.changeDisplay(displayIndex);
2251
- slot.updateDisplayVisible(frame.visible);
2252
- if (displayIndex >= 0) {
2253
- if (!isNaN(frame.zOrder) && frame.zOrder != slot._tweenZOrder) {
2254
- slot._tweenZOrder = frame.zOrder;
2255
- this._armature._slotsZOrderChanged = true;
2256
- }
2257
- }
2258
- }
2259
- var eventData = void 0;
2260
- if (frame.event && this._armature._eventDispatcher.hasEvent(dragonBones.EventType.BONE_FRAME_EVENT)) {
2261
- eventData = dragonBones.EventData.borrowObject(dragonBones.EventType.BONE_FRAME_EVENT);
2262
- eventData.armature = this._armature;
2263
- eventData.bone = this;
2264
- eventData.animationState = animationState;
2265
- eventData.frameLabel = frame.event;
2266
- eventData.frame = frame;
2267
- this._armature._eventDataList.push_back(eventData);
2268
- }
2269
- if (frame.sound && DBSoundEventDispatcher && DBSoundEventDispatcher.hasEvent(dragonBones.EventType.SOUND)) {
2270
- eventData = dragonBones.EventData.borrowObject(dragonBones.EventData.EventType.SOUND);
2271
- eventData.armature = this._armature;
2272
- eventData.bone = this;
2273
- eventData.animationState = animationState;
2274
- eventData.sound = frame.sound;
2275
- DBSoundEventDispatcher.dispatchEvent(eventData);
2276
- }
2277
- if (frame.action) {
2278
- var len = this._slotList.length;
2279
- for (var j = 0; j < len; ++j) {
2280
- if (this._slotList[j]._childArmature) {
2281
- this._slotList[j]._childArmature._animation.gotoAndPlay(frame.action);
2282
- }
2283
- }
2284
- }
2285
- }
2286
- },
2287
- /** @protected */
2288
- addState: function (timelineState) {
2289
- if (this._timelineStateList.indexOf(timelineState) < 0) {
2290
- this._timelineStateList.push(timelineState);
2291
- this._timelineStateList.sort(dragonBones.Bone.sortState);
2292
- }
2293
- },
2294
- /** @protected */
2295
- removeState: function (timelineState) {
2296
- var index = this._timelineStateList.indexOf(timelineState);
2297
- if (index >= 0) {
2298
- this._timelineStateList.splice(index, 1);
2299
- }
2300
- },
2301
- /** @protected */
2302
- blendingTimeline: function () {
2303
- var i = this._timelineStateList.length;
2304
- var timelineState;
2305
- var transform;
2306
- var pivot;
2307
- var weight;
2308
- if (i == 1) {
2309
- timelineState = this._timelineStateList[0];
2310
- transform = timelineState._transform;
2311
- pivot = timelineState._pivot;
2312
- timelineState._weight = timelineState._animationState.getCurrentWeight();
2313
- weight = timelineState._weight;
2314
- this._tween.x = transform.x * weight;
2315
- this._tween.y = transform.y * weight;
2316
- this._tween.skewX = transform.skewX * weight;
2317
- this._tween.skewY = transform.skewY * weight;
2318
- this._tween.scaleX = transform.scaleX * weight;
2319
- this._tween.scaleY = transform.scaleY * weight;
2320
- this._tweenPivot.x = pivot.x * weight;
2321
- this._tweenPivot.y = pivot.y * weight;
2322
- }
2323
- else if (i > 1) {
2324
- var prevLayer = this._timelineStateList[i - 1]._animationState.getLayer();
2325
- var currentLayer = 0;
2326
- var weigthLeft = 1;
2327
- var layerTotalWeight = 0;
2328
- var x = 0;
2329
- var y = 0;
2330
- var skewX = 0;
2331
- var skewY = 0;
2332
- var scaleX = 0;
2333
- var scaleY = 0;
2334
- var pivotX = 0;
2335
- var pivotY = 0;
2336
- while (i--) {
2337
- timelineState = this._timelineStateList[i];
2338
- currentLayer = timelineState._animationState.getLayer();
2339
- if (prevLayer != currentLayer) {
2340
- if (layerTotalWeight >= weigthLeft) {
2341
- timelineState._weight = 0;
2342
- break;
2343
- }
2344
- else {
2345
- weigthLeft -= layerTotalWeight;
2346
- }
2347
- }
2348
- prevLayer = currentLayer;
2349
- timelineState._weight = timelineState._animationState.getCurrentWeight() * weigthLeft;
2350
- weight = timelineState._weight;
2351
- //timelineState
2352
- if (weight && timelineState._blendEnabled) {
2353
- transform = timelineState._transform;
2354
- pivot = timelineState._pivot;
2355
- x += transform.x * weight;
2356
- y += transform.y * weight;
2357
- skewX += transform.skewX * weight;
2358
- skewY += transform.skewY * weight;
2359
- scaleX += transform.scaleX * weight;
2360
- scaleY += transform.scaleY * weight;
2361
- pivotX += pivot.x * weight;
2362
- pivotY += pivot.y * weight;
2363
- layerTotalWeight += weight;
2364
- }
2365
- }
2366
- this._tween.x = x;
2367
- this._tween.y = y;
2368
- this._tween.skewX = skewX;
2369
- this._tween.skewY = skewY;
2370
- this._tween.scaleX = scaleX;
2371
- this._tween.scaleY = scaleY;
2372
- this._tweenPivot.x = pivotX;
2373
- this._tweenPivot.y = pivotY;
2374
- }
2375
- }
2376
- });
2377
- dragonBones.Bone.sortState = function (a, b) {
2378
- return a._animationState.getLayer() < b._animationState.getLayer() ? -1 : 1;
2379
- };
2380
- dragonBones.Slot = dragonBones.Object.extend({
2381
- _isShowDisplay: false,
2382
- _displayIndex: 0,
2383
- _originZOrder: 0,
2384
- _tweenZOrder: 0,
2385
- _offsetZOrder: 0,
2386
- _blendMode: null,
2387
- _colorTransform: null,
2388
- _displayList: null,
2389
- _slotData: null,
2390
- _display: null,
2391
- _childArmature: null,
2392
- ctor: function (slotData) {
2393
- dragonBones.Object.prototype.ctor.call(this);
2394
- this._displayIndex = -1;
2395
- this._blendMode = dragonBones.BlendMode.BM_NORMAL;
2396
- this._slotData = slotData;
2397
- this._childArmature = null;
2398
- this._display = null;
2399
- this.inheritRotation = true;
2400
- this.inheritScale = true;
2401
- this._displayList = [];
2402
- this._colorTransform = new dragonBones.ColorTransform();
2403
- },
2404
- dispose: function () {
2405
- dragonBones.Object.prototype.dispose.call(this);
2406
- this._displayList.length = 0;
2407
- this._slotData = null;
2408
- this._childArmature = null;
2409
- this._display = null;
2410
- },
2411
- getBoundingBox: function () { },
2412
- getDisplayIndex: function () {
2413
- return this._displayIndex;
2414
- },
2415
- isShowDisplay: function () {
2416
- return this._isShowDisplay;
2417
- },
2418
- getSlotData: function () {
2419
- return this._slotData;
2420
- },
2421
- getZOrder: function () {
2422
- return this._originZOrder + this._tweenZOrder + this._offsetZOrder;
2423
- },
2424
- setZOrder: function (zorder) {
2425
- if (this.getZOrder() != zorder) {
2426
- this._offsetZOrder = zorder - this._originZOrder - this._tweenZOrder;
2427
- if (this._armature) {
2428
- this._armature._slotsZOrderChanged = true;
2429
- }
2430
- }
2431
- },
2432
- getDisplay: function () {
2433
- return this._display;
2434
- },
2435
- setDisplay: function (display, displayType, disposeExisting) {
2436
- if (displayType === undefined) {
2437
- displayType = dragonBones.DisplayType.DT_IMAGE;
2438
- }
2439
- if (disposeExisting === undefined) {
2440
- disposeExisting = true;
2441
- }
2442
- if (this._displayIndex < 0) {
2443
- this._isShowDisplay = true;
2444
- this._displayIndex = 0;
2445
- }
2446
- if (this._displayList[this._displayIndex] == display) {
2447
- return;
2448
- }
2449
- this._displayList[this._displayIndex] = display;
2450
- this.updateSlotDisplay(disposeExisting);
2451
- },
2452
- getChildArmature: function () {
2453
- return this._childArmature;
2454
- },
2455
- setChildArmature: function (childArmature, disposeExisting) {
2456
- if (disposeExisting === undefined) {
2457
- disposeExisting = true;
2458
- }
2459
- this.setDisplay(childArmature, dragonBones.DisplayType.DT_ARMATURE, disposeExisting);
2460
- },
2461
- getDisplayList: function () {
2462
- return this._displayList;
2463
- },
2464
- setDisplayList: function (displayList, disposeExisting) {
2465
- if (disposeExisting === undefined) {
2466
- disposeExisting = true;
2467
- }
2468
- if (this._displayIndex < 0) {
2469
- this._isShowDisplay = true;
2470
- this._displayIndex = 0;
2471
- }
2472
- if (disposeExisting) {
2473
- this.disposeDisplayList();
2474
- this._childArmature = null;
2475
- this._display = null;
2476
- }
2477
- // copy
2478
- this._displayList = displayList;
2479
- var displayIndexBackup = this._displayIndex;
2480
- this._displayIndex = -1;
2481
- this.changeDisplay(displayIndexBackup);
2482
- },
2483
- setVisible: function (visible) {
2484
- if (this._visible != visible) {
2485
- this._visible = visible;
2486
- this.updateDisplayVisible(this._visible);
2487
- }
2488
- },
2489
- update: function () {
2490
- // console.log('update', this._parent._needUpdate)
2491
- if (this._parent._needUpdate <= 0) {
2492
- return;
2493
- }
2494
- var x = this.origin.x + this.offset.x + this._parent._tweenPivot.x;
2495
- var y = this.origin.y + this.offset.y + this._parent._tweenPivot.y;
2496
- var parentMatrix = this._parent.globalTransformMatrix;
2497
- this.globalTransformMatrix.tx = this.global.x = parentMatrix.a * x + parentMatrix.c * y + parentMatrix.tx;
2498
- this.globalTransformMatrix.ty = this.global.y = parentMatrix.d * y + parentMatrix.b * x + parentMatrix.ty;
2499
- //globalTransformMatrix.tx = global.x = parentMatrix.a * x * _parent.global.scaleX + parentMatrix.c * y * _parent.global.scaleY + parentMatrix.tx;
2500
- //globalTransformMatrix.ty = global.y = parentMatrix.d * y * _parent.global.scaleY + parentMatrix.b * x * _parent.global.scaleX + parentMatrix.ty;
2501
- if (this.inheritRotation) {
2502
- this.global.skewX = this.origin.skewX + this.offset.skewX + this._parent.global.skewX;
2503
- this.global.skewY = this.origin.skewY + this.offset.skewY + this._parent.global.skewY;
2504
- }
2505
- else {
2506
- this.global.skewX = this.origin.skewX + this.offset.skewX;
2507
- this.global.skewY = this.origin.skewY + this.offset.skewY;
2508
- }
2509
- if (this.inheritScale) {
2510
- this.global.scaleX = this.origin.scaleX * this.offset.scaleX * this._parent.global.scaleX;
2511
- this.global.scaleY = this.origin.scaleY * this.offset.scaleY * this._parent.global.scaleY;
2512
- }
2513
- else {
2514
- this.global.scaleX = this.origin.scaleX * this.offset.scaleX;
2515
- this.global.scaleY = this.origin.scaleY * this.offset.scaleY;
2516
- }
2517
- this.globalTransformMatrix.a = this.global.scaleX * Math.cos(this.global.skewY);
2518
- this.globalTransformMatrix.b = this.global.scaleX * Math.sin(this.global.skewY);
2519
- this.globalTransformMatrix.c = -this.global.scaleY * Math.sin(this.global.skewX);
2520
- this.globalTransformMatrix.d = this.global.scaleY * Math.cos(this.global.skewX);
2521
- this.updateDisplayTransform();
2522
- },
2523
- changeDisplay: function (displayIndex) {
2524
- if (displayIndex === void 0) { displayIndex = 0; }
2525
- if (displayIndex < 0) {
2526
- if (this._isShowDisplay) {
2527
- this._isShowDisplay = false;
2528
- this.removeDisplayFromContainer();
2529
- this.updateChildArmatureAnimation();
2530
- }
2531
- }
2532
- else if (this._displayList.length > 0) {
2533
- if (displayIndex >= this._displayList.length) {
2534
- displayIndex = this._displayList.length - 1;
2535
- }
2536
- if (this._displayIndex != displayIndex) {
2537
- this._isShowDisplay = true;
2538
- this._displayIndex = displayIndex;
2539
- this.updateSlotDisplay(false);
2540
- if (this._slotData &&
2541
- this._slotData.displayDataList.length > 0 &&
2542
- this._displayIndex < this._slotData.displayDataList.length) {
2543
- this.origin = this._slotData.displayDataList[this._displayIndex].transform;
2544
- }
2545
- }
2546
- else if (!this._isShowDisplay) {
2547
- this._isShowDisplay = true;
2548
- if (this._armature) {
2549
- this._armature._slotsZOrderChanged = true;
2550
- this.addDisplayToContainer(this._armature, -1);
2551
- }
2552
- this.updateChildArmatureAnimation();
2553
- }
2554
- }
2555
- },
2556
- updateSlotDisplay: function (disposeExisting) {
2557
- var currentDisplayIndex = -1;
2558
- if (this._display) {
2559
- currentDisplayIndex = this.getDisplayZIndex();
2560
- this.removeDisplayFromContainer();
2561
- }
2562
- if (disposeExisting) {
2563
- if (this._childArmature) {
2564
- this._childArmature.dispose();
2565
- this._childArmature = null;
2566
- }
2567
- else if (this._display) {
2568
- this.disposeDisplay();
2569
- this._display = null;
2570
- }
2571
- }
2572
- this.stopChildArmatureAnimation();
2573
- var display = this._displayList[this._displayIndex];
2574
- // console.log('updateSlotDisplay', display);
2575
- if (display) {
2576
- if (display instanceof dragonBones.Armature) {
2577
- this._childArmature = display;
2578
- this._display = this._childArmature._display;
2579
- }
2580
- else {
2581
- this._childArmature = null;
2582
- this._display = display;
2583
- }
2584
- }
2585
- else {
2586
- this._display = null;
2587
- this._childArmature = null;
2588
- }
2589
- this.playChildArmatureAnimation();
2590
- this.updateDisplay(this._display);
2591
- if (this._display) {
2592
- if (this._armature && this._isShowDisplay) {
2593
- if (currentDisplayIndex < 0) {
2594
- this._armature._slotsZOrderChanged = true;
2595
- this.addDisplayToContainer(this._armature, currentDisplayIndex);
2596
- }
2597
- else {
2598
- this.addDisplayToContainer(this._armature, currentDisplayIndex);
2599
- }
2600
- }
2601
- if (this._blendMode != dragonBones.BlendMode.BM_NORMAL) {
2602
- this.updateDisplayBlendMode(this._blendMode);
2603
- }
2604
- else if (this._slotData) {
2605
- this.updateDisplayBlendMode(this._slotData.blendMode);
2606
- }
2607
- this.updateDisplayColor(this._colorTransform.alphaOffset, this._colorTransform.redOffset, this._colorTransform.greenOffset, this._colorTransform.blueOffset, this._colorTransform.alphaMultiplier, this._colorTransform.redMultiplier, this._colorTransform.greenMultiplier, this._colorTransform.blueMultiplier);
2608
- this.updateDisplayVisible(this._visible);
2609
- this.updateDisplayTransform();
2610
- }
2611
- },
2612
- updateDisplayColor: function (aOffset, rOffset, gOffset, bOffset, aMultiplier, rMultiplier, gMultiplier, bMultiplier) {
2613
- this._colorTransform.alphaOffset = aOffset;
2614
- this._colorTransform.redOffset = rOffset;
2615
- this._colorTransform.greenOffset = gOffset;
2616
- this._colorTransform.blueOffset = bOffset;
2617
- this._colorTransform.alphaMultiplier = aMultiplier;
2618
- this._colorTransform.redMultiplier = rMultiplier;
2619
- this._colorTransform.greenMultiplier = gMultiplier;
2620
- this._colorTransform.blueMultiplier = bMultiplier;
2621
- },
2622
- updateChildArmatureAnimation: function () {
2623
- if (this._isShowDisplay) {
2624
- this.playChildArmatureAnimation();
2625
- }
2626
- else {
2627
- this.stopChildArmatureAnimation();
2628
- }
2629
- },
2630
- playChildArmatureAnimation: function () {
2631
- if (this._childArmature && this._childArmature._isInheritAnimation) {
2632
- if (this._armature &&
2633
- this._armature._animation._lastAnimationState &&
2634
- this._childArmature._animation.hasAnimation(this._armature._animation._lastAnimationState.name)) {
2635
- this._childArmature._animation.gotoAndPlay(this._armature._animation._lastAnimationState.name);
2636
- }
2637
- else {
2638
- this._childArmature._animation.play();
2639
- }
2640
- }
2641
- },
2642
- stopChildArmatureAnimation: function () {
2643
- if (this._childArmature) {
2644
- this._childArmature._animation.stop();
2645
- this._childArmature._animation._lastAnimationState = null;
2646
- }
2647
- },
2648
- getDisplayZIndex: function () { },
2649
- addDisplayToContainer: function (container, zIndex) { },
2650
- removeDisplayFromContainer: function () { },
2651
- disposeDisplay: function () { },
2652
- disposeDisplayList: function () { },
2653
- updateDisplay: function (display) { },
2654
- updateDisplayBlendMode: function (blendMode) { },
2655
- updateDisplayVisible: function (visible) { },
2656
- updateDisplayTransform: function () { },
2657
- /** @protected */
2658
- setArmature: function (armature) {
2659
- dragonBones.Object.prototype.setArmature.call(this, armature);
2660
- if (this._armature) {
2661
- this._armature._slotsZOrderChanged = true;
2662
- this.addDisplayToContainer(this._armature, -1);
2663
- }
2664
- else {
2665
- this.removeDisplayFromContainer();
2666
- }
2667
- }
2668
- });
2669
- /*----------------------------------------------------------------------core部分---------------------------------------------------------------*/
2670
- /*----------------------------------------------------------------------event部分---------------------------------------------------------------*/
2671
- dragonBones.EventData = cc.Class.extend({
2672
- frameLabel: null,
2673
- sound: null,
2674
- armature: null,
2675
- bone: null,
2676
- animationState: null,
2677
- frame: null,
2678
- _type: 0,
2679
- ctor: function (type, armatureTarget) {
2680
- if (type === undefined) {
2681
- type = dragonBones.EventType._ERROR;
2682
- }
2683
- if (armatureTarget === undefined) {
2684
- armatureTarget = null;
2685
- }
2686
- this._type = type;
2687
- this.armature = armatureTarget;
2688
- },
2689
- getType: function () {
2690
- return this._type;
2691
- },
2692
- getStringType: function () {
2693
- return dragonBones.EventData.typeToString(this._type);
2694
- },
2695
- clear: function () {
2696
- this.armature = null;
2697
- this.bone = null;
2698
- this.animationState = null;
2699
- this.frame = null;
2700
- this.frameLabel = null;
2701
- this.sound = null;
2702
- },
2703
- copy: function (copyData) {
2704
- this._type = copyData._type;
2705
- this.frameLabel = copyData.frameLabel;
2706
- this.sound = copyData.sound;
2707
- this.armature = copyData.armature;
2708
- this.bone = copyData.bone;
2709
- this.animationState = copyData.animationState;
2710
- this.frame = copyData.frame;
2711
- }
2712
- });
2713
- dragonBones.EventData.Z_ORDER_UPDATED = 'zorderUpdate';
2714
- dragonBones.EventData.ANIMATION_FRAME_EVENT = 'animationFrameEvent';
2715
- dragonBones.EventData.BONE_FRAME_EVENT = 'boneFrameEvent';
2716
- dragonBones.EventData.SOUND = 'sound';
2717
- dragonBones.EventData.FADE_IN = 'fadeIn';
2718
- dragonBones.EventData.FADE_OUT = 'fadeOut';
2719
- dragonBones.EventData.START = 'start';
2720
- dragonBones.EventData.COMPLETE = 'complete';
2721
- dragonBones.EventData.LOOP_COMPLETE = 'loopComplete';
2722
- dragonBones.EventData.FADE_IN_COMPLETE = 'fadeInComplete';
2723
- dragonBones.EventData.FADE_OUT_COMPLETE = 'fadeOutComplete';
2724
- dragonBones.EventData._ERROR = 'error';
2725
- var DBEventDataPool = [];
2726
- dragonBones.EventData._pool = DBEventDataPool;
2727
- dragonBones.EventData.typeToString = function (eventType) {
2728
- switch (eventType) {
2729
- case dragonBones.EventType.Z_ORDER_UPDATED:
2730
- return dragonBones.EventData.Z_ORDER_UPDATED;
2731
- case dragonBones.EventType.ANIMATION_FRAME_EVENT:
2732
- return dragonBones.EventData.ANIMATION_FRAME_EVENT;
2733
- case dragonBones.EventType.BONE_FRAME_EVENT:
2734
- return dragonBones.EventData.BONE_FRAME_EVENT;
2735
- case dragonBones.EventType.SOUND:
2736
- return dragonBones.EventData.SOUND;
2737
- case dragonBones.EventType.FADE_IN:
2738
- return dragonBones.EventData.FADE_IN;
2739
- case dragonBones.EventType.FADE_OUT:
2740
- return dragonBones.EventData.FADE_OUT;
2741
- case dragonBones.EventType.START:
2742
- return dragonBones.EventData.START;
2743
- case dragonBones.EventType.COMPLETE:
2744
- return dragonBones.EventData.COMPLETE;
2745
- case dragonBones.EventType.LOOP_COMPLETE:
2746
- return dragonBones.EventData.LOOP_COMPLETE;
2747
- case dragonBones.EventType.FADE_IN_COMPLETE:
2748
- return dragonBones.EventData.FADE_IN_COMPLETE;
2749
- case dragonBones.EventType.FADE_OUT_COMPLETE:
2750
- return dragonBones.EventData.FADE_OUT_COMPLETE;
2751
- default:
2752
- break;
2753
- }
2754
- // throw
2755
- return dragonBones.EventData._ERROR;
2756
- };
2757
- dragonBones.EventData.borrowObject = function (eventType) {
2758
- if (DBEventDataPool.length == 0) {
2759
- return new dragonBones.EventData(eventType, null);
2760
- }
2761
- var eventData = DBEventDataPool.pop();
2762
- eventData._type = eventType;
2763
- return eventData;
2764
- };
2765
- dragonBones.EventData.returnObject = function (eventData) {
2766
- if (DBEventDataPool.indexOf(eventData) < 0) {
2767
- DBEventDataPool.push(eventData);
2768
- }
2769
- eventData.clear();
2770
- };
2771
- dragonBones.EventData.clearObjects = function () {
2772
- var i = DBEventDataPool.length;
2773
- while (--i >= 0) {
2774
- DBEventDataPool[i].clear();
2775
- }
2776
- DBEventDataPool.length = 0;
2777
- };
2778
- /*----------------------------------------------------------------------event部分---------------------------------------------------------------*/
2779
- /*----------------------------------------------------------------------factories部分---------------------------------------------------------------*/
2780
- dragonBones.BaseFactory = cc.Class.extend({
2781
- autoSearchDragonBonesData: false,
2782
- autoSearchTexture: false,
2783
- _dragonBonesDataMap: null,
2784
- _textureAtlasMap: null,
2785
- _currentDragonBonesDataName: null,
2786
- _currentTextureAtlasName: null,
2787
- ctor: function () {
2788
- this._dragonBonesDataMap = {};
2789
- this._textureAtlasMap = {};
2790
- },
2791
- dispose: function (disposeData) {
2792
- if (disposeData === undefined) {
2793
- disposeData = true;
2794
- }
2795
- if (disposeData) {
2796
- var key = void 0;
2797
- for (key in this._dragonBonesDataMap) {
2798
- this._dragonBonesDataMap[key].dispose();
2799
- }
2800
- for (key in this._textureAtlasMap) {
2801
- this._textureAtlasMap[key].dispose();
2802
- }
2803
- }
2804
- this._dragonBonesDataMap = null;
2805
- this._textureAtlasMap = null;
2806
- },
2807
- getDragonBonesDataMap: function () {
2808
- return this._dragonBonesDataMap;
2809
- },
2810
- getTextureAtlasMap: function () {
2811
- return this._textureAtlasMap;
2812
- },
2813
- getDragonBonesData: function (name) {
2814
- return this._dragonBonesDataMap[name];
2815
- },
2816
- addDragonBonesData: function (data, name) {
2817
- if (!data) {
2818
- throw new Error();
2819
- }
2820
- name = name || data.name;
2821
- if (!name) {
2822
- throw new Error('Unnamed data!');
2823
- }
2824
- if (this._dragonBonesDataMap[name]) {
2825
- throw new Error();
2826
- }
2827
- this._dragonBonesDataMap[name] = data;
2828
- },
2829
- removeDragonBonesData: function (name, disposeData) {
2830
- if (disposeData === undefined) {
2831
- disposeData = true;
2832
- }
2833
- var data = this._dragonBonesDataMap[name];
2834
- if (data) {
2835
- if (disposeData) {
2836
- data.dispose();
2837
- }
2838
- delete this._dragonBonesDataMap[name];
2839
- data = null;
2840
- }
2841
- },
2842
- getTextureAtlas: function (name) {
2843
- return this._textureAtlasMap[name];
2844
- },
2845
- addTextureAtlas: function (textureAtlas, name) {
2846
- var key = textureAtlas.textureAtlasData.name || name;
2847
- // console.log('textureAtlas', name, key, textureAtlas)
2848
- if (!key) {
2849
- throw new Error();
2850
- }
2851
- if (this._textureAtlasMap[key]) {
2852
- throw new Error();
2853
- }
2854
- this._textureAtlasMap[key] = textureAtlas;
2855
- },
2856
- removeTextureAtlas: function (name, disposeData) {
2857
- if (disposeData === undefined) {
2858
- disposeData = true;
2859
- }
2860
- var data = this._textureAtlasMap[name];
2861
- if (data) {
2862
- if (disposeData) {
2863
- data.dispose();
2864
- }
2865
- delete this._textureAtlasMap[name];
2866
- data = null;
2867
- }
2868
- },
2869
- buildArmature: function (armatureName, skinName, animationName, dragonBonesName, textureAtlasName) {
2870
- if (skinName === undefined) {
2871
- skinName = null;
2872
- }
2873
- if (animationName === undefined) {
2874
- animationName = null;
2875
- }
2876
- if (dragonBonesName === undefined) {
2877
- dragonBonesName = null;
2878
- }
2879
- if (textureAtlasName === undefined) {
2880
- textureAtlasName = null;
2881
- }
2882
- var dragonBonesData = null;
2883
- var armatureData = null;
2884
- var animationArmatureData = null;
2885
- var skinData = null;
2886
- var skinDataCopy = null;
2887
- var key;
2888
- console.log('this._dragonBonesDataMap', this._dragonBonesDataMap);
2889
- if (dragonBonesName) {
2890
- dragonBonesData = this._dragonBonesDataMap[dragonBonesName];
2891
- if (dragonBonesData) {
2892
- armatureData = dragonBonesData.getArmatureData(armatureName);
2893
- this._currentDragonBonesDataName = dragonBonesName;
2894
- this._currentTextureAtlasName = textureAtlasName == null ? this._currentDragonBonesDataName : textureAtlasName;
2895
- }
2896
- }
2897
- if (!armatureData) {
2898
- var searchType = (dragonBonesName == null ? dragonBones.AutoSearchType.AST_ALL : (this.autoSearchDragonBonesData ? dragonBones.AutoSearchType.AST_AUTO : dragonBones.AutoSearchType.AST_NONE));
2899
- if (searchType != dragonBones.AutoSearchType.AST_NONE) {
2900
- for (key in this._dragonBonesDataMap) {
2901
- dragonBonesData = this._dragonBonesDataMap[key];
2902
- if (searchType == dragonBones.AutoSearchType.AST_ALL || dragonBonesData.autoSearch) {
2903
- armatureData = dragonBonesData.getArmatureData(armatureName);
2904
- if (armatureData) {
2905
- this._currentDragonBonesDataName = key;
2906
- this._currentTextureAtlasName = this._currentDragonBonesDataName;
2907
- break;
2908
- }
2909
- }
2910
- }
2911
- }
2912
- }
2913
- if (!armatureData) {
2914
- return null;
2915
- }
2916
- if (animationName && animationName != armatureName) {
2917
- animationArmatureData = dragonBonesData.getArmatureData(animationName);
2918
- if (!animationArmatureData) {
2919
- for (key in this._dragonBonesDataMap) {
2920
- dragonBonesData = this._dragonBonesDataMap[key];
2921
- animationArmatureData = dragonBonesData.getArmatureData(animationName);
2922
- if (animationArmatureData) {
2923
- break;
2924
- }
2925
- }
2926
- }
2927
- if (animationArmatureData) {
2928
- skinDataCopy = animationArmatureData.getSkinData('');
2929
- }
2930
- }
2931
- skinData = armatureData.getSkinData(skinName);
2932
- console.log('skinData', skinData);
2933
- var armature = this.generateArmature(armatureData);
2934
- armature.name = armatureName;
2935
- if (animationArmatureData) {
2936
- armature.getAnimation().setAnimationDataList(animationArmatureData.animationDataList);
2937
- }
2938
- else {
2939
- armature.getAnimation().setAnimationDataList(armatureData.animationDataList);
2940
- }
2941
- this.buildBones(armature, armatureData);
2942
- if (skinData) {
2943
- this.buildSlots(armature, armatureData, skinData, skinDataCopy);
2944
- }
2945
- // update armature pose
2946
- armature.getAnimation().play();
2947
- armature.advanceTime(0);
2948
- armature.getAnimation().stop();
2949
- return armature;
2950
- },
2951
- getTextureDisplay: function (textureName, textureAtlasName, displayData) {
2952
- // console.log('getTextureDisplay', textureName, textureAtlasName, displayData)
2953
- if (textureAtlasName === undefined) {
2954
- textureAtlasName = null;
2955
- }
2956
- if (displayData === undefined) {
2957
- displayData = null;
2958
- }
2959
- var textureAtlas = null;
2960
- var textureData = null;
2961
- var key;
2962
- if (textureAtlasName) {
2963
- textureAtlas = this._textureAtlasMap[textureAtlasName];
2964
- if (textureAtlas) {
2965
- textureData = textureAtlas.textureAtlasData.getTextureData(textureName);
2966
- }
2967
- }
2968
- if (!textureData) {
2969
- var searchType = (textureAtlasName == null ? dragonBones.AutoSearchType.AST_ALL : (this.autoSearchTexture ? dragonBones.AutoSearchType.AST_AUTO : dragonBones.AutoSearchType.AST_NONE));
2970
- if (searchType != dragonBones.AutoSearchType.AST_NONE) {
2971
- for (key in this._textureAtlasMap) {
2972
- textureAtlas = this._textureAtlasMap[key];
2973
- if (searchType == dragonBones.AutoSearchType.AST_ALL || textureAtlas.textureAtlasData.autoSearch) {
2974
- textureData = textureAtlas.textureAtlasData.getTextureData(textureName);
2975
- if (textureData) {
2976
- break;
2977
- }
2978
- }
2979
- }
2980
- }
2981
- }
2982
- if (!textureData) {
2983
- return null;
2984
- }
2985
- if (!displayData) {
2986
- var data = this._dragonBonesDataMap[textureAtlas.textureAtlasData.name];
2987
- if (data) {
2988
- var dragonBonesData = data;
2989
- for (var i = 0, l1 = dragonBonesData.armatureDataList.length; i < l1; ++i) {
2990
- for (var j = 0, l2 = dragonBonesData.armatureDataList[i].skinDataList.length; j < l2; ++j) {
2991
- for (var k = 0, l3 = dragonBonesData.armatureDataList[i].skinDataList[j].slotDataList.length; k < l3; ++k) {
2992
- for (var m = 0, l4 = dragonBonesData.armatureDataList[i].skinDataList[j].slotDataList[k].displayDataList.length; m < l4; ++m) {
2993
- displayData = dragonBonesData.armatureDataList[i].skinDataList[j].slotDataList[k].displayDataList[m];
2994
- if (displayData.name != textureName) {
2995
- displayData = null;
2996
- }
2997
- else {
2998
- break;
2999
- }
3000
- }
3001
- if (displayData) {
3002
- break;
3003
- }
3004
- }
3005
- if (displayData) {
3006
- break;
3007
- }
3008
- }
3009
- if (displayData) {
3010
- break;
3011
- }
3012
- }
3013
- }
3014
- }
3015
- return this.generateDisplay(textureAtlas, textureData, displayData);
3016
- },
3017
- buildBones: function (armature, armatureData) {
3018
- var boneData;
3019
- var bone;
3020
- for (var i = 0, l = armatureData.boneDataList.length; i < l; ++i) {
3021
- boneData = armatureData.boneDataList[i];
3022
- bone = new dragonBones.Bone();
3023
- bone.name = boneData.name;
3024
- bone.inheritRotation = boneData.inheritRotation;
3025
- bone.inheritScale = boneData.inheritScale;
3026
- // copy
3027
- bone.origin = boneData.transform;
3028
- if (armatureData.getBoneData(boneData.parent)) {
3029
- armature.addBone(bone, boneData.parent);
3030
- }
3031
- else {
3032
- armature.addBone(bone);
3033
- }
3034
- }
3035
- },
3036
- buildSlots: function (armature, armatureData, skinData, skinDataCopy) {
3037
- console.log('buildSlots', armature, armatureData, skinData);
3038
- var slotData;
3039
- var bone;
3040
- var slot;
3041
- var displayList;
3042
- var frameDisplay;
3043
- for (var i = 0, l1 = skinData.slotDataList.length; i < l1; ++i) {
3044
- slotData = skinData.slotDataList[i];
3045
- bone = armature.getBone(slotData.parent);
3046
- // console.log('bone', bone, slotData)
3047
- if (!bone) {
3048
- continue;
3049
- }
3050
- slot = this.generateSlot(slotData);
3051
- slot.name = slotData.name;
3052
- slot._originZOrder = slotData.zOrder;
3053
- slot._slotData = slotData;
3054
- displayList = [];
3055
- frameDisplay = null;
3056
- for (var j = 0, l2 = slotData.displayDataList.length; j < l2; ++j) {
3057
- var displayData = slotData.displayDataList[j];
3058
- switch (displayData.type) {
3059
- case dragonBones.DisplayType.DT_ARMATURE:
3060
- {
3061
- var displayDataCopy = null;
3062
- if (skinDataCopy) {
3063
- var slotDataCopy = skinDataCopy.getSlotData(slotData.name);
3064
- if (slotDataCopy) {
3065
- displayDataCopy = slotDataCopy.displayDataList[i];
3066
- }
3067
- }
3068
- var currentDragonBonesDataName = this._currentDragonBonesDataName;
3069
- var currentTextureAtlasName = this._currentTextureAtlasName;
3070
- var childArmature = this.buildArmature(displayData.name, '', displayDataCopy ? displayDataCopy.name : '', currentDragonBonesDataName, currentTextureAtlasName);
3071
- displayList.push(childArmature);
3072
- this._currentDragonBonesDataName = currentDragonBonesDataName;
3073
- this._currentTextureAtlasName = currentTextureAtlasName;
3074
- break;
3075
- }
3076
- case dragonBones.DisplayType.DT_IMAGE:
3077
- {
3078
- var display = this.getTextureDisplay(displayData.name, this._currentTextureAtlasName, displayData);
3079
- displayList.push(display);
3080
- break;
3081
- }
3082
- /*
3083
- case dragonBones.DisplayType.DT_FRAME:
3084
- {
3085
- break;
3086
- }
3087
-
3088
- case dragonBones.DisplayType.DT_TEXT:
3089
- {
3090
- break;
3091
- }
3092
- */
3093
- default:
3094
- displayList.push(null);
3095
- break;
3096
- }
3097
- }
3098
- bone.addChild(slot);
3099
- if (displayList.length > 0) {
3100
- slot.setDisplayList(displayList, false);
3101
- }
3102
- }
3103
- },
3104
- generateArmature: function (armatureData) { },
3105
- generateSlot: function (slotData) { },
3106
- generateDisplay: function (textureAtlas, textureData, displayData) { }
3107
- });
3108
- /*----------------------------------------------------------------------factories部分---------------------------------------------------------------*/
3109
- /*----------------------------------------------------------------------geoms部分---------------------------------------------------------------*/
3110
- dragonBones.ColorTransform = cc.Class.extend({
3111
- alphaMultiplier: 1,
3112
- redMultiplier: 1,
3113
- greenMultiplier: 1,
3114
- blueMultiplier: 1,
3115
- alphaOffset: 0,
3116
- redOffset: 0,
3117
- greenOffset: 0,
3118
- blueOffset: 0,
3119
- ator: function () { }
3120
- });
3121
- dragonBones.Point = cc.Class.extend({
3122
- x: 0,
3123
- y: 0,
3124
- ctor: function () { }
3125
- });
3126
- dragonBones.Matrix = cc.Class.extend({
3127
- a: 0,
3128
- b: 0,
3129
- c: 0,
3130
- d: 0,
3131
- tx: 0,
3132
- ty: 0,
3133
- ctor: function () { },
3134
- invert: function () {
3135
- var a0 = this.a;
3136
- var b0 = this.b;
3137
- var c0 = this.c;
3138
- var d0 = this.d;
3139
- var tx0 = this.tx;
3140
- var ty0 = this.ty;
3141
- var determinant = 1 / (a0 * d0 - b0 * c0);
3142
- this.a = determinant * d0;
3143
- this.b = -determinant * b0;
3144
- this.c = -determinant * c0;
3145
- this.d = determinant * a0;
3146
- this.tx = determinant * (c0 * ty0 - d0 * tx0);
3147
- this.ty = determinant * (b0 * tx0 - a0 * ty0);
3148
- },
3149
- transformPoint: function (point) {
3150
- var x = point.x;
3151
- var y = point.y;
3152
- point.x = this.a * x + this.c * y + this.tx;
3153
- point.y = this.d * y + this.b * x + this.ty;
3154
- }
3155
- });
3156
- dragonBones.Rectangle = cc.Class.extend({
3157
- x: 0,
3158
- y: 0,
3159
- width: 0,
3160
- height: 0,
3161
- ctor: function (x, y, width, height) {
3162
- if (x === undefined) {
3163
- x = 0;
3164
- }
3165
- if (y === undefined) {
3166
- y = 0;
3167
- }
3168
- if (width === undefined) {
3169
- width = 0;
3170
- }
3171
- if (height === undefined) {
3172
- height = 0;
3173
- }
3174
- this.x = x;
3175
- this.y = y;
3176
- this.width = width;
3177
- this.height = height;
3178
- }
3179
- });
3180
- dragonBones.Transform = cc.Class.extend({
3181
- x: 0,
3182
- y: 0,
3183
- skewX: 0,
3184
- skewY: 0,
3185
- scaleX: 1,
3186
- scaleY: 1,
3187
- ctor: function () { },
3188
- getRotation: function () {
3189
- return this.skewX;
3190
- },
3191
- setRotation: function (value) {
3192
- this.skewX = this.skewY = value;
3193
- },
3194
- copy: function (transform) {
3195
- this.x = transform.x;
3196
- this.y = transform.y;
3197
- this.skewX = transform.skewX;
3198
- this.skewY = transform.skewY;
3199
- this.scaleX = transform.scaleX;
3200
- this.scaleY = transform.scaleY;
3201
- },
3202
- toMatrix: function (matrix, keepScale) {
3203
- if (keepScale === undefined)
3204
- keepScale = false;
3205
- if (keepScale) {
3206
- matrix.a = this.scaleX * Math.cos(this.skewY);
3207
- matrix.b = this.scaleX * Math.sin(this.skewY);
3208
- matrix.c = -this.scaleY * Math.sin(this.skewX);
3209
- matrix.d = this.scaleY * Math.cos(this.skewX);
3210
- }
3211
- else {
3212
- matrix.a = Math.cos(this.skewY);
3213
- matrix.b = Math.sin(this.skewY);
3214
- matrix.c = -Math.sin(this.skewX);
3215
- matrix.d = Math.cos(this.skewX);
3216
- }
3217
- matrix.tx = this.x;
3218
- matrix.ty = this.y;
3219
- },
3220
- /**
3221
- * @function
3222
- * @param {dragonBones.Transform}.
3223
- */
3224
- transformWith: function (parent) {
3225
- var matrix = new dragonBones.Matrix();
3226
- parent.toMatrix(matrix, true);
3227
- matrix.invert();
3228
- var x0 = this.x;
3229
- var y0 = this.y;
3230
- this.x = matrix.a * x0 + matrix.c * y0 + matrix.tx;
3231
- this.y = matrix.d * y0 + matrix.b * x0 + matrix.ty;
3232
- this.skewX = DBUtils.TransformUtil.formatRadian(this.skewX - parent.skewX);
3233
- this.skewY = DBUtils.TransformUtil.formatRadian(this.skewY - parent.skewY);
3234
- }
3235
- });
3236
- /*----------------------------------------------------------------------geoms部分---------------------------------------------------------------*/
3237
- /*----------------------------------------------------------------------objects部分---------------------------------------------------------------*/
3238
- dragonBones.Timeline = cc.Class.extend({
3239
- duration: 0,
3240
- scale: 0,
3241
- frameList: null,
3242
- ctor: function () {
3243
- this.duration = 0;
3244
- this.scale = 1;
3245
- this.frameList = [];
3246
- },
3247
- dispose: function () {
3248
- var i = this.frameList.length;
3249
- while (i--) {
3250
- this.frameList[i].dispose();
3251
- }
3252
- this.frameList.length = 0;
3253
- this.frameList = null;
3254
- }
3255
- });
3256
- dragonBones.AnimationData = dragonBones.Timeline.extend({
3257
- autoTween: false,
3258
- frameRate: 0,
3259
- playTimes: 0,
3260
- fadeTime: 0,
3261
- // use frame tweenEase, NaN
3262
- // overwrite frame tweenEase, [-1, 0):ease in, 0:line easing, (0, 1]:ease out, (1, 2]:ease in out
3263
- tweenEasing: 0,
3264
- name: null,
3265
- timelineList: null,
3266
- hideTimelineList: null,
3267
- ctor: function () {
3268
- dragonBones.Timeline.prototype.ctor.call(this);
3269
- this.frameRate = 30;
3270
- this.playTimes = 1;
3271
- this.tweenEasing = dragonBones.USE_FRAME_TWEEN_EASING;
3272
- this.timelineList = [];
3273
- this.hideTimelineList = [];
3274
- },
3275
- getTimeline: function (timelineName) {
3276
- for (var i = 0, l = this.timelineList.length; i < l; ++i) {
3277
- if (this.timelineList[i].name == timelineName) {
3278
- return this.timelineList[i];
3279
- }
3280
- }
3281
- return null;
3282
- },
3283
- dispose: function () {
3284
- dragonBones.Timeline.prototype.dispose.call(this);
3285
- for (var timelineName in this.timelineList) {
3286
- (this.timelineList[timelineName]).dispose();
3287
- }
3288
- this.timelineList = null;
3289
- }
3290
- });
3291
- dragonBones.ArmatureData = cc.Class.extend({
3292
- boneDataList: null,
3293
- skinDataList: null,
3294
- animationDataList: null,
3295
- //(DB#1)缺少碰撞数据
3296
- ctor: function () {
3297
- this.boneDataList = [];
3298
- this.skinDataList = [];
3299
- this.animationDataList = [];
3300
- },
3301
- dispose: function () {
3302
- var i = this.boneDataList.length;
3303
- while (i--) {
3304
- this.boneDataList[i].dispose();
3305
- }
3306
- i = this.skinDataList.length;
3307
- while (i--) {
3308
- this.skinDataList[i].dispose();
3309
- }
3310
- i = this.animationDataList.length;
3311
- while (i--) {
3312
- this.animationDataList[i].dispose();
3313
- }
3314
- this.boneDataList.length = 0;
3315
- this.skinDataList.length = 0;
3316
- this.animationDataList.length = 0;
3317
- this.boneDataList = null;
3318
- this.skinDataList = null;
3319
- this.animationDataList = null;
3320
- },
3321
- getBoneData: function (boneName) {
3322
- var i = this.boneDataList.length;
3323
- while (i--) {
3324
- if (this.boneDataList[i].name == boneName) {
3325
- return this.boneDataList[i];
3326
- }
3327
- }
3328
- return null;
3329
- },
3330
- getSkinData: function (skinName) {
3331
- if (!skinName) {
3332
- return this.skinDataList[0];
3333
- }
3334
- var i = this.skinDataList.length;
3335
- while (i--) {
3336
- if (this.skinDataList[i].name == skinName) {
3337
- return this.skinDataList[i];
3338
- }
3339
- }
3340
- return null;
3341
- },
3342
- getAnimationData: function (animationName) {
3343
- var i = this.animationDataList.length;
3344
- while (i--) {
3345
- if (this.animationDataList[i].name == animationName) {
3346
- return this.animationDataList[i];
3347
- }
3348
- }
3349
- return null;
3350
- },
3351
- addBoneData: function (boneData) {
3352
- if (!boneData) {
3353
- throw new Error();
3354
- }
3355
- if (this.boneDataList.indexOf(boneData) < 0) {
3356
- this.boneDataList[this.boneDataList.length] = boneData;
3357
- }
3358
- else {
3359
- throw new Error();
3360
- }
3361
- },
3362
- addSkinData: function (skinData) {
3363
- if (!skinData) {
3364
- throw new Error();
3365
- }
3366
- if (this.skinDataList.indexOf(skinData) < 0) {
3367
- this.skinDataList[this.skinDataList.length] = skinData;
3368
- }
3369
- else {
3370
- throw new Error();
3371
- }
3372
- },
3373
- addAnimationData: function (animationData) {
3374
- if (!animationData) {
3375
- throw new Error();
3376
- }
3377
- if (this.animationDataList.indexOf(animationData) < 0) {
3378
- this.animationDataList[this.animationDataList.length] = animationData;
3379
- }
3380
- },
3381
- sortBoneDataList: function () {
3382
- var i = this.boneDataList.length;
3383
- if (i == 0) {
3384
- return;
3385
- }
3386
- var helpArray = [];
3387
- while (i--) {
3388
- var boneData = this.boneDataList[i];
3389
- var level = 0;
3390
- var parentData = boneData;
3391
- while (parentData && parentData.parent) {
3392
- level++;
3393
- parentData = this.getBoneData(parentData.parent);
3394
- }
3395
- helpArray[i] = { level: level, boneData: boneData };
3396
- }
3397
- helpArray.sort(this.sortBoneData);
3398
- i = helpArray.length;
3399
- while (i--) {
3400
- this.boneDataList[i] = helpArray[i].boneData;
3401
- }
3402
- },
3403
- sortBoneData: function (object1, object2) {
3404
- return object1.level > object2.level ? 1 : -1;
3405
- }
3406
- });
3407
- dragonBones.BoneData = cc.Class.extend({
3408
- name: null,
3409
- parent: null,
3410
- length: 0,
3411
- global: null,
3412
- transform: null,
3413
- inheritScale: false,
3414
- inheritRotation: false,
3415
- //(DB#1)缺少碰撞数据
3416
- ctor: function () {
3417
- this.length = 0;
3418
- this.global = new dragonBones.Transform();
3419
- this.transform = new dragonBones.Transform();
3420
- this.inheritRotation = true;
3421
- },
3422
- dispose: function () {
3423
- this.global = null;
3424
- this.transform = null;
3425
- }
3426
- });
3427
- dragonBones.DisplayData = cc.Class.extend({
3428
- name: null,
3429
- type: null,
3430
- transform: null,
3431
- pivot: null,
3432
- ctor: function () {
3433
- this.transform = new dragonBones.Transform();
3434
- this.pivot = new dragonBones.Point();
3435
- },
3436
- dispose: function () {
3437
- this.transform = null;
3438
- this.pivot = null;
3439
- }
3440
- });
3441
- dragonBones.DragonBonesData = cc.Class.extend({
3442
- autoSearch: false,
3443
- name: null,
3444
- armatureDataList: null,
3445
- ctor: function () {
3446
- this.armatureDataList = [];
3447
- },
3448
- dispose: function () {
3449
- var i = this.armatureDataList.length;
3450
- while (i--) {
3451
- this.armatureDataList[i].dispose();
3452
- }
3453
- this.armatureDataList.length = 0;
3454
- this.armatureDataList = null;
3455
- },
3456
- getArmatureData: function (armatureName) {
3457
- var i = this.armatureDataList.length;
3458
- while (i--) {
3459
- if (this.armatureDataList[i].name == armatureName) {
3460
- return this.armatureDataList[i];
3461
- }
3462
- }
3463
- return null;
3464
- }
3465
- });
3466
- dragonBones.Frame = cc.Class.extend(/** @lends dragonBones.Frame# */ {
3467
- position: 0,
3468
- duration: 0,
3469
- frameType: null,
3470
- action: null,
3471
- event: null,
3472
- sound: null,
3473
- eventParameters: null,
3474
- eventParametersParsed: null,
3475
- ctor: function () {
3476
- this.frameType = dragonBones.FT_FRAME;
3477
- },
3478
- dispose: function () {
3479
- if (this.eventParametersParsed != null)
3480
- this.eventParametersParsed = null;
3481
- }
3482
- });
3483
- dragonBones.SkinData = cc.Class.extend({
3484
- name: null,
3485
- slotDataList: null,
3486
- ctor: function () {
3487
- this.slotDataList = [];
3488
- },
3489
- dispose: function () {
3490
- var i = this.slotDataList.length;
3491
- while (i--) {
3492
- this.slotDataList[i].dispose();
3493
- }
3494
- this.slotDataList.length = 0;
3495
- this.slotDataList = null;
3496
- },
3497
- getSlotData: function (slotName) {
3498
- var i = this.slotDataList.length;
3499
- while (i--) {
3500
- if (this.slotDataList[i].name == slotName) {
3501
- return this.slotDataList[i];
3502
- }
3503
- }
3504
- return null;
3505
- },
3506
- addSlotData: function (slotData) {
3507
- if (!slotData) {
3508
- throw new Error();
3509
- }
3510
- if (this.slotDataList.indexOf(slotData) < 0) {
3511
- this.slotDataList[this.slotDataList.length] = slotData;
3512
- }
3513
- else {
3514
- throw new Error();
3515
- }
3516
- }
3517
- });
3518
- dragonBones.SlotData = cc.Class.extend({
3519
- name: null,
3520
- parent: null,
3521
- zOrder: 0,
3522
- blendMode: null,
3523
- displayDataList: null,
3524
- ctor: function () {
3525
- this.displayDataList = [];
3526
- },
3527
- dispose: function () {
3528
- var i = this.displayDataList.length;
3529
- while (i--) {
3530
- this.displayDataList[i].dispose();
3531
- }
3532
- this.displayDataList.length = 0;
3533
- this.displayDataList = null;
3534
- },
3535
- getDisplayData: function (slotName) {
3536
- var i = this.displayDataList.length;
3537
- while (i--) {
3538
- if (this.displayDataList[i].name == slotName) {
3539
- return this.displayDataList[i];
3540
- }
3541
- }
3542
- return null;
3543
- },
3544
- addDisplayData: function (slotData) {
3545
- if (!slotData) {
3546
- throw new Error();
3547
- }
3548
- if (this.displayDataList.indexOf(slotData) < 0) {
3549
- this.displayDataList[this.displayDataList.length] = slotData;
3550
- }
3551
- else {
3552
- throw new Error();
3553
- }
3554
- }
3555
- });
3556
- dragonBones.TransformFrame = dragonBones.Frame.extend({
3557
- visible: false,
3558
- tweenScale: false,
3559
- tweenRotate: 0,
3560
- displayIndex: 0,
3561
- zOrder: 0,
3562
- // NaN:no tween, 10:auto tween, [-1, 0):ease in, 0:line easing, (0, 1]:ease out, (1, 2]:ease in out
3563
- tweenEasing: 0,
3564
- global: null,
3565
- transform: null,
3566
- pivot: null,
3567
- scaleOffset: null,
3568
- color: null,
3569
- ctor: function () {
3570
- dragonBones.Frame.prototype.ctor.call(this);
3571
- this.visible = true;
3572
- this.tweenScale = true;
3573
- this.tweenEasing = dragonBones.NO_TWEEN_EASING;
3574
- this.frameType = dragonBones.FT_TRANSFORM_FRAME;
3575
- this.global = new dragonBones.Transform();
3576
- this.transform = new dragonBones.Transform();
3577
- this.pivot = new dragonBones.Point();
3578
- this.scaleOffset = new dragonBones.Point();
3579
- },
3580
- dispose: function () {
3581
- dragonBones.Frame.prototype.dispose.call(this);
3582
- this.global = null;
3583
- this.transform = null;
3584
- this.pivot = null;
3585
- this.scaleOffset = null;
3586
- this.color = null;
3587
- }
3588
- });
3589
- dragonBones.TransformTimeline = dragonBones.Timeline.extend({
3590
- transformed: false,
3591
- offset: 0,
3592
- name: null,
3593
- originTransform: null,
3594
- originPivot: null,
3595
- ctor: function () {
3596
- dragonBones.Timeline.prototype.ctor.call(this);
3597
- this.originTransform = new dragonBones.Transform();
3598
- this.originPivot = new dragonBones.Point();
3599
- },
3600
- dispose: function () {
3601
- dragonBones.Timeline.prototype.dispose.call(this);
3602
- this.originTransform = null;
3603
- this.originPivot = null;
3604
- }
3605
- });
3606
- /*----------------------------------------------------------------------objects部分---------------------------------------------------------------*/
3607
- /*----------------------------------------------------------------------parsers部分---------------------------------------------------------------*/
3608
- dragonBones.BaseDataParser = cc.Class.extend({
3609
- ctor: function () { },
3610
- parseTextureAtlasData: function (rawTextureAtlasData, scale) {
3611
- if (scale === undefined) {
3612
- scale = 1;
3613
- }
3614
- },
3615
- parseDragonBonesData: function (rawDragonBonesData, scale) {
3616
- if (scale === undefined) {
3617
- scale = 1;
3618
- }
3619
- }
3620
- });
3621
- dragonBones.BaseDataParser.transformArmatureData = function (armatureData) {
3622
- var i = armatureData.boneDataList.length;
3623
- var boneData;
3624
- var parentBoneData;
3625
- while (--i >= 0) {
3626
- boneData = armatureData.boneDataList[i];
3627
- if (boneData && boneData.parent) {
3628
- parentBoneData = armatureData.getBoneData(boneData.parent);
3629
- if (parentBoneData) {
3630
- boneData.transform = boneData.global;
3631
- boneData.transform.transformWith(parentBoneData.global);
3632
- }
3633
- }
3634
- }
3635
- };
3636
- dragonBones.BaseDataParser.transformArmatureDataAnimations = function (armatureData) {
3637
- for (var i = 0, l = armatureData.animationDataList.length; i < l; ++i) {
3638
- dragonBones.BaseDataParser.transformAnimationData(armatureData.animationDataList[i], armatureData);
3639
- }
3640
- };
3641
- dragonBones.BaseDataParser.transformAnimationData = function (animationData, armatureData) {
3642
- var skinData = armatureData.getSkinData(null);
3643
- var boneData;
3644
- var timeline;
3645
- var slotData;
3646
- var originTransform;
3647
- var originPivot;
3648
- var prevFrame;
3649
- var frame;
3650
- var dLX;
3651
- for (var i = 0, l = armatureData.boneDataList.length; i < l; ++i) {
3652
- boneData = armatureData.boneDataList[i];
3653
- timeline = animationData.getTimeline(boneData.name);
3654
- if (!timeline) {
3655
- continue;
3656
- }
3657
- slotData = null;
3658
- if (skinData) {
3659
- for (var j = 0, len = skinData.slotDataList.length; j < len; ++j) {
3660
- slotData = skinData.slotDataList[j];
3661
- if (slotData.parent == boneData.name) {
3662
- break;
3663
- }
3664
- }
3665
- }
3666
- originTransform = null;
3667
- originPivot = null;
3668
- prevFrame = null;
3669
- for (var k = 0, l1 = timeline.frameList.length; k < l1; ++k) {
3670
- frame = timeline.frameList[k];
3671
- dragonBones.BaseDataParser.setFrameTransform(animationData, armatureData, boneData, frame);
3672
- frame.transform.x -= boneData.transform.x;
3673
- frame.transform.y -= boneData.transform.y;
3674
- frame.transform.skewX -= boneData.transform.skewX;
3675
- frame.transform.skewY -= boneData.transform.skewY;
3676
- frame.transform.scaleX -= boneData.transform.scaleX;
3677
- frame.transform.scaleY -= boneData.transform.scaleY;
3678
- if (!timeline.transformed && slotData) {
3679
- frame.zOrder -= slotData.zOrder;
3680
- }
3681
- if (!originTransform) {
3682
- // copy
3683
- timeline.originTransform.copy(frame.transform);
3684
- originTransform = timeline.originTransform;
3685
- originTransform.skewX = DBUtils.TransformUtil.formatRadian(originTransform.skewX);
3686
- originTransform.skewY = DBUtils.TransformUtil.formatRadian(originTransform.skewY);
3687
- // copy
3688
- timeline.originPivot.x = frame.pivot.x;
3689
- timeline.originPivot.y = frame.pivot.y;
3690
- originPivot = timeline.originPivot;
3691
- }
3692
- frame.transform.x -= originTransform.x;
3693
- frame.transform.y -= originTransform.y;
3694
- frame.transform.skewX = DBUtils.TransformUtil.formatRadian(frame.transform.skewX - originTransform.skewX);
3695
- frame.transform.skewY = DBUtils.TransformUtil.formatRadian(frame.transform.skewY - originTransform.skewY);
3696
- frame.transform.scaleX -= originTransform.scaleX;
3697
- frame.transform.scaleY -= originTransform.scaleY;
3698
- if (!timeline.transformed) {
3699
- frame.pivot.x -= originPivot.x;
3700
- frame.pivot.y -= originPivot.y;
3701
- }
3702
- if (prevFrame) {
3703
- dLX = frame.transform.skewX - prevFrame.transform.skewX;
3704
- if (prevFrame.tweenRotate) {
3705
- if (prevFrame.tweenRotate > 0) {
3706
- if (dLX < 0) {
3707
- frame.transform.skewX += Math.PI * 2;
3708
- frame.transform.skewY += Math.PI * 2;
3709
- }
3710
- if (prevFrame.tweenRotate > 1) {
3711
- frame.transform.skewX += Math.PI * 2 * (prevFrame.tweenRotate - 1);
3712
- frame.transform.skewY += Math.PI * 2 * (prevFrame.tweenRotate - 1);
3713
- }
3714
- }
3715
- else {
3716
- if (dLX > 0) {
3717
- frame.transform.skewX -= Math.PI * 2;
3718
- frame.transform.skewY -= Math.PI * 2;
3719
- }
3720
- if (prevFrame.tweenRotate < 1) {
3721
- frame.transform.skewX += Math.PI * 2 * (prevFrame.tweenRotate + 1);
3722
- frame.transform.skewY += Math.PI * 2 * (prevFrame.tweenRotate + 1);
3723
- }
3724
- }
3725
- }
3726
- else {
3727
- frame.transform.skewX = prevFrame.transform.skewX + DBUtils.TransformUtil.formatRadian(frame.transform.skewX - prevFrame.transform.skewX);
3728
- frame.transform.skewY = prevFrame.transform.skewY + DBUtils.TransformUtil.formatRadian(frame.transform.skewY - prevFrame.transform.skewY);
3729
- }
3730
- }
3731
- prevFrame = frame;
3732
- }
3733
- timeline.transformed = true;
3734
- }
3735
- };
3736
- dragonBones.BaseDataParser.addHideTimeline = function (animationData, armatureData) {
3737
- var boneData;
3738
- for (var i = 0, l = armatureData.boneDataList.length; i < l; ++i) {
3739
- boneData = armatureData.boneDataList[i];
3740
- if (!animationData.getTimeline(boneData.name)) {
3741
- if (animationData.hideTimelineList.indexOf(boneData.name) < 0) {
3742
- animationData.hideTimelineList.push(boneData.name);
3743
- }
3744
- }
3745
- }
3746
- };
3747
- dragonBones.BaseDataParser.setFrameTransform = function (animationData, armatureData, boneData, frame) {
3748
- frame.transform.copy(frame.global);
3749
- var parentData = armatureData.getBoneData(boneData.parent);
3750
- if (parentData) {
3751
- var parentTimeline = animationData.getTimeline(parentData.name);
3752
- if (parentTimeline) {
3753
- var parentTimelineList = [];
3754
- var parentDataList = [];
3755
- while (parentTimeline) {
3756
- parentTimelineList.push(parentTimeline);
3757
- parentDataList.push(parentData);
3758
- parentData = armatureData.getBoneData(parentData.parent);
3759
- if (parentData) {
3760
- parentTimeline = animationData.getTimeline(parentData.name);
3761
- }
3762
- else {
3763
- parentTimeline = null;
3764
- }
3765
- }
3766
- var helpMatrix = new dragonBones.Matrix();
3767
- var currentTransform = new dragonBones.Transform();
3768
- var globalTransform = null;
3769
- for (var i = parentTimelineList.length; i--;) {
3770
- parentTimeline = parentTimelineList[i];
3771
- parentData = parentDataList[i];
3772
- dragonBones.BaseDataParser.getTimelineTransform(parentTimeline, frame.position, currentTransform, !globalTransform);
3773
- if (globalTransform) {
3774
- globalTransform.skewX += currentTransform.skewX + parentTimeline.originTransform.skewX + parentData.transform.skewX;
3775
- globalTransform.skewY += currentTransform.skewY + parentTimeline.originTransform.skewY + parentData.transform.skewY;
3776
- globalTransform.scaleX = currentTransform.scaleX + parentTimeline.originTransform.scaleX + parentData.transform.scaleX;
3777
- globalTransform.scaleY = currentTransform.scaleY + parentTimeline.originTransform.scaleY + parentData.transform.scaleY;
3778
- var x = currentTransform.x + parentTimeline.originTransform.x + parentData.transform.x;
3779
- var y = currentTransform.y + parentTimeline.originTransform.y + parentData.transform.y;
3780
- globalTransform.x = helpMatrix.a * x + helpMatrix.c * y + helpMatrix.tx;
3781
- globalTransform.y = helpMatrix.d * y + helpMatrix.b * x + helpMatrix.ty;
3782
- }
3783
- else {
3784
- globalTransform = new dragonBones.Transform();
3785
- globalTransform.copy(currentTransform);
3786
- }
3787
- globalTransform.toMatrix(helpMatrix, true);
3788
- }
3789
- frame.transform.transformWith(globalTransform);
3790
- }
3791
- }
3792
- };
3793
- dragonBones.BaseDataParser.getTimelineTransform = function (timeline, position, retult, isGlobal) {
3794
- var currentFrame;
3795
- var progress;
3796
- var tweenEasing;
3797
- for (var i = 0, l = timeline.frameList.length; i < l; ++i) {
3798
- currentFrame = timeline.frameList[i];
3799
- if (currentFrame.position <= position && currentFrame.position + currentFrame.duration > position) {
3800
- if (i == timeline.frameList.length - 1 || position == currentFrame.position) {
3801
- //copy
3802
- retult.copy(isGlobal ? currentFrame.global : currentFrame.transform);
3803
- }
3804
- else {
3805
- progress = (position - currentFrame.position) / currentFrame.duration;
3806
- tweenEasing = currentFrame.tweenEasing;
3807
- if (tweenEasing && tweenEasing != dragonBones.NO_TWEEN_EASING && tweenEasing != dragonBones.AUTO_TWEEN_EASING) {
3808
- progress = DBUtils.TransformUtil.getEaseValue(progress, tweenEasing);
3809
- }
3810
- var nextFrame = timeline.frameList[i + 1];
3811
- var currentTransform = isGlobal ? currentFrame.global : currentFrame.transform;
3812
- var nextTransform = isGlobal ? nextFrame.global : nextFrame.transform;
3813
- retult.x = currentTransform.x + (nextTransform.x - currentTransform.x) * progress;
3814
- retult.y = currentTransform.y + (nextTransform.y - currentTransform.y) * progress;
3815
- retult.skewX = DBUtils.TransformUtil.formatRadian(currentTransform.skewX + (nextTransform.skewX - currentTransform.skewX) * progress);
3816
- retult.skewY = DBUtils.TransformUtil.formatRadian(currentTransform.skewY + (nextTransform.skewY - currentTransform.skewY) * progress);
3817
- retult.scaleX = currentTransform.scaleX + (nextTransform.scaleX - currentTransform.scaleX) * progress;
3818
- retult.scaleY = currentTransform.scaleY + (nextTransform.scaleY - currentTransform.scaleY) * progress;
3819
- }
3820
- break;
3821
- }
3822
- }
3823
- };
3824
- dragonBones.ObjectDataParser = dragonBones.BaseDataParser.extend({
3825
- _textureScale: 0,
3826
- _armatureScale: 0,
3827
- _frameRate: 0,
3828
- ctor: function () {
3829
- dragonBones.BaseDataParser.prototype.ctor.call(this);
3830
- this._textureScale = 1;
3831
- this._armatureScale = 1;
3832
- this._frameRate = 30;
3833
- },
3834
- parseTextureAtlasData: function (rawTextureAtlasData, scale) {
3835
- if (scale === undefined) {
3836
- scale = 1;
3837
- }
3838
- this._textureScale = scale;
3839
- var textureAtlasData = new dragonBones.TextureAtlasData();
3840
- textureAtlasData.name = rawTextureAtlasData[DBConstValues.A_NAME];
3841
- textureAtlasData.imagePath = rawTextureAtlasData[DBConstValues.A_IMAGE_PATH]; //还差图片路径BUG #0
3842
- var textureData;
3843
- var subTextureList = rawTextureAtlasData[DBConstValues.SUB_TEXTURE];
3844
- for (var key in subTextureList) {
3845
- textureData = this.parseTextureData(subTextureList[key]);
3846
- textureAtlasData.textureDataList.push(textureData);
3847
- }
3848
- return textureAtlasData;
3849
- },
3850
- parseDragonBonesData: function (rawDragonBonesData, scale) {
3851
- if (scale === void 0) { scale = 1; }
3852
- this._armatureScale = scale;
3853
- //const XMLElement *dragonBonesXML = static_cast<const XMLElement*>(rawDragonBonesData);
3854
- //std::string version = dragonBonesXML.Attribute(DBConstValues.A_VERSION);
3855
- this._frameRate = this.getNumber(rawDragonBonesData, DBConstValues.A_FRAME_RATE, 0, 0);
3856
- var dragonBonesData = new dragonBones.DragonBonesData();
3857
- dragonBonesData.name = rawDragonBonesData[DBConstValues.A_NAME];
3858
- var armatureData;
3859
- var armatureList = rawDragonBonesData[DBConstValues.ARMATURE];
3860
- for (var key in armatureList) {
3861
- armatureData = this.parseArmatureData(armatureList[key]); //存在问题
3862
- dragonBonesData.armatureDataList.push(armatureData);
3863
- }
3864
- return dragonBonesData;
3865
- },
3866
- parseTextureData: function (textureXML) {
3867
- var textureData = new dragonBones.TextureData();
3868
- textureData.name = textureXML[DBConstValues.A_NAME];
3869
- textureData.rotated = textureXML[DBConstValues.A_ROTATED] == 'true';
3870
- textureData.region.x = this.getNumber(textureXML, DBConstValues.A_X, 0) / this._textureScale;
3871
- textureData.region.y = this.getNumber(textureXML, DBConstValues.A_Y, 0) / this._textureScale;
3872
- textureData.region.width = this.getNumber(textureXML, DBConstValues.A_WIDTH, 0) / this._textureScale;
3873
- textureData.region.height = this.getNumber(textureXML, DBConstValues.A_HEIGHT, 0) / this._textureScale;
3874
- var frameWidth = this.getNumber(textureXML, DBConstValues.A_FRAME_WIDTH, 0) / this._textureScale;
3875
- var frameHeight = this.getNumber(textureXML, DBConstValues.A_FRAME_HEIGHT, 0) / this._textureScale;
3876
- if (frameWidth > 0 && frameHeight > 0) {
3877
- textureData.frame = new dragonBones.Rectangle();
3878
- textureData.frame.x = this.getNumber(textureXML, DBConstValues.A_FRAME_X, 0) / this._textureScale;
3879
- textureData.frame.y = this.getNumber(textureXML, DBConstValues.A_FRAME_Y, 0) / this._textureScale;
3880
- textureData.frame.width = frameWidth;
3881
- textureData.frame.height = frameHeight;
3882
- }
3883
- return textureData;
3884
- },
3885
- parseArmatureData: function (armatureXML) {
3886
- var armatureData = new dragonBones.ArmatureData();
3887
- armatureData.name = armatureXML[DBConstValues.A_NAME];
3888
- var key;
3889
- var boneList = armatureXML[DBConstValues.BONE];
3890
- var boneData;
3891
- for (key in boneList) {
3892
- boneData = this.parseBoneData(boneList[key]);
3893
- armatureData.boneDataList.push(boneData);
3894
- }
3895
- var skinList = armatureXML[DBConstValues.SKIN];
3896
- var slotsList = armatureXML[DBConstValues.SLOT];
3897
- console.log(slotsList);
3898
- var skinData;
3899
- for (key in skinList) {
3900
- skinData = this.parseSkinData(skinList[key], slotsList);
3901
- armatureData.skinDataList.push(skinData);
3902
- }
3903
- dragonBones.BaseDataParser.transformArmatureData(armatureData);
3904
- armatureData.sortBoneDataList();
3905
- var animationList = armatureXML[DBConstValues.ANIMATION];
3906
- var animationData;
3907
- for (key in animationList) {
3908
- animationData = this.parseAnimationData(animationList[key], armatureData);
3909
- armatureData.animationDataList.push(animationData);
3910
- }
3911
- //不解析碰撞数据
3912
- /*for (const XMLElement *rectangleXML = armatureXML.FirstChildElement(DBConstValues.RECTANGLE); rectangleXML; rectangleXML = rectangleXML.NextSiblingElement(DBConstValues.RECTANGLE))
3913
- {
3914
- RectangleData *rectangleData = parseRectangleData(rectangleXML);
3915
- armatureData.areaDataList.push_back(rectangleData);
3916
- }
3917
-
3918
- for (const XMLElement *ellipseXML = armatureXML.FirstChildElement(DBConstValues.ELLIPSE); ellipseXML; ellipseXML = ellipseXML.NextSiblingElement(DBConstValues.ELLIPSE))
3919
- {
3920
- EllipseData *ellipseData = parseEllipseData(ellipseXML);
3921
- armatureData.areaDataList.push_back(ellipseData);
3922
- }*/
3923
- return armatureData;
3924
- },
3925
- parseBoneData: function (boneXML) {
3926
- var boneData = new dragonBones.BoneData();
3927
- boneData.name = boneXML[DBConstValues.A_NAME];
3928
- var parent = boneXML[DBConstValues.A_PARENT];
3929
- if (parent) {
3930
- boneData.parent = parent;
3931
- }
3932
- boneData.length = this.getNumber(boneXML, DBConstValues.A_LENGTH, 0, 0);
3933
- boneData.inheritRotation = this.getBoolean(boneXML, DBConstValues.A_INHERIT_ROTATION, true);
3934
- boneData.inheritScale = this.getBoolean(boneXML, DBConstValues.A_INHERIT_SCALE, false);
3935
- var transformXML = boneXML[DBConstValues.TRANSFORM];
3936
- if (transformXML) {
3937
- this.parseTransform(transformXML, boneData.global);
3938
- }
3939
- boneData.transform.copy(boneData.global);
3940
- //不解析碰撞数据
3941
- /*for (const XMLElement *rectangleXML = boneXML.FirstChildElement(DBConstValues.RECTANGLE); rectangleXML; rectangleXML = rectangleXML.NextSiblingElement(DBConstValues.RECTANGLE))
3942
- {
3943
- RectangleData *rectangleData = parseRectangleData(rectangleXML);
3944
- boneData.areaDataList.push_back(rectangleData);
3945
- }
3946
-
3947
- for (const XMLElement *ellipseXML = boneXML.FirstChildElement(DBConstValues.ELLIPSE); ellipseXML; ellipseXML = ellipseXML.NextSiblingElement(DBConstValues.ELLIPSE))
3948
- {
3949
- EllipseData *ellipseData = parseEllipseData(ellipseXML);
3950
- boneData.areaDataList.push_back(ellipseData);
3951
- }*/
3952
- return boneData;
3953
- },
3954
- parseSkinData: function (skinXML, slotsList) {
3955
- var skinData = new dragonBones.SkinData();
3956
- skinData.name = skinXML[DBConstValues.A_NAME];
3957
- var slotList = skinXML[DBConstValues.SLOT];
3958
- var slotData;
3959
- for (var key in slotList) {
3960
- slotData = this.parseSlotData(slotList[key], slotsList);
3961
- skinData.slotDataList.push(slotData);
3962
- }
3963
- return skinData;
3964
- },
3965
- parseSlotData: function (slotXML, slotsList) {
3966
- if (slotsList === void 0) { slotsList = []; }
3967
- var slotData = new dragonBones.SlotData();
3968
- slotData.name = slotXML[DBConstValues.A_NAME];
3969
- slotData.parent = slotXML[DBConstValues.A_PARENT] ||
3970
- slotsList.find(function (slot) { return slot.name == slotData.name; }).parent;
3971
- slotData.zOrder = this.getNumber(slotXML, DBConstValues.A_Z_ORDER, 0, 0);
3972
- if (slotXML[DBConstValues.A_BLENDMODE]) {
3973
- slotData.blendMode = dragonBones.getBlendModeByString(slotXML[DBConstValues.A_BLENDMODE]);
3974
- }
3975
- var displayList = slotXML[DBConstValues.DISPLAY];
3976
- var displayData;
3977
- for (var key in displayList) {
3978
- displayData = this.parseDisplayData(displayList[key]);
3979
- slotData.displayDataList.push(displayData);
3980
- }
3981
- return slotData;
3982
- },
3983
- parseDisplayData: function (displayXML) {
3984
- var displayData = new dragonBones.DisplayData();
3985
- displayData.name = displayXML[DBConstValues.A_NAME];
3986
- displayData.type = dragonBones.getDisplayTypeByString(displayXML[DBConstValues.A_TYPE]);
3987
- var scalingGridXML = displayXML[DBConstValues.SCALING_GRID];
3988
- if (scalingGridXML) {
3989
- displayData.scalingGrid = true;
3990
- displayData.scalingGridLeft = this.getNumber(scalingGridXML, DBConstValues.A_LEFT, 0, 0);
3991
- displayData.scalingGridRight = this.getNumber(scalingGridXML, DBConstValues.A_RIGHT, 0, 0);
3992
- displayData.scalingGridTop = this.getNumber(scalingGridXML, DBConstValues.A_TOP, 0, 0);
3993
- displayData.scalingGridBottom = this.getNumber(scalingGridXML, DBConstValues.A_BOTTOM, 0, 0);
3994
- }
3995
- else {
3996
- displayData.scalingGrid = false;
3997
- }
3998
- var transformXML = displayXML[DBConstValues.TRANSFORM];
3999
- if (transformXML) {
4000
- this.parseTransform(transformXML, displayData.transform);
4001
- this.parsePivot(transformXML, displayData.pivot);
4002
- }
4003
- //不解析文本数据
4004
- /*const XMLElement *textXML = displayXML.FirstChildElement(DBConstValues.TEXT);
4005
- if (textXML)
4006
- {
4007
- displayData.textData = new TextData();
4008
- parseTextData(*textXML, *displayData.textData);
4009
- }*/
4010
- return displayData;
4011
- },
4012
- parseAnimationData: function (animationXML, armatureData) {
4013
- var animationData = new dragonBones.AnimationData();
4014
- animationData.name = animationXML[DBConstValues.A_NAME];
4015
- animationData.frameRate = this._frameRate;
4016
- animationData.duration = Math.round(this.getNumber(animationXML, DBConstValues.A_DURATION, 1, 1) * 1000 / this._frameRate);
4017
- animationData.playTimes = this.getNumber(animationXML, DBConstValues.A_LOOP, 1, 1);
4018
- animationData.fadeTime = this.getNumber(animationXML, DBConstValues.A_FADE_IN_TIME, 0, 0);
4019
- animationData.scale = this.getNumber(animationXML, DBConstValues.A_SCALE, 1, 1);
4020
- // use frame tweenEase, NaN
4021
- // overwrite frame tweenEase, [-1, 0):ease in, 0:line easing, (0, 1]:ease out, (1, 2]:ease in out
4022
- animationData.tweenEasing = this.getNumber(animationXML, DBConstValues.A_TWEEN_EASING, dragonBones.USE_FRAME_TWEEN_EASING, dragonBones.USE_FRAME_TWEEN_EASING);
4023
- animationData.autoTween = this.getBoolean(animationXML, DBConstValues.A_AUTO_TWEEN, true);
4024
- var key;
4025
- var frameObjectList = animationXML[DBConstValues.FRAME];
4026
- var frame;
4027
- for (key in frameObjectList) {
4028
- frame = this.parseMainFrame(frameObjectList[key]);
4029
- animationData.frameList.push(frame);
4030
- }
4031
- this.parseTimeline(animationXML, animationData);
4032
- var timelineObjectList = animationXML[DBConstValues.TIMELINE];
4033
- var timeline;
4034
- for (key in timelineObjectList) {
4035
- timeline = this.parseTransformTimeline(timelineObjectList[key], animationData.duration);
4036
- animationData.timelineList.push(timeline);
4037
- }
4038
- dragonBones.BaseDataParser.addHideTimeline(animationData, armatureData);
4039
- dragonBones.BaseDataParser.transformAnimationData(animationData, armatureData);
4040
- return animationData;
4041
- },
4042
- parseTransformTimeline: function (timelineXML, duration) {
4043
- var timeline = new dragonBones.TransformTimeline();
4044
- timeline.name = timelineXML[DBConstValues.A_NAME];
4045
- timeline.scale = this.getNumber(timelineXML, DBConstValues.A_SCALE, 1, 0);
4046
- timeline.offset = this.getNumber(timelineXML, DBConstValues.A_OFFSET, 0, 0);
4047
- timeline.duration = duration;
4048
- var frameList = timelineXML[DBConstValues.FRAME];
4049
- var frame;
4050
- for (var key in frameList) {
4051
- frame = this.parseTransformFrame(frameList[key]);
4052
- timeline.frameList.push(frame);
4053
- }
4054
- this.parseTimeline(timelineXML, timeline);
4055
- return timeline;
4056
- },
4057
- parseMainFrame: function (frameXML) {
4058
- var frame = new dragonBones.Frame();
4059
- this.parseFrame(frameXML, frame);
4060
- return frame;
4061
- },
4062
- parseTransformFrame: function (frameXML) {
4063
- var frame = new dragonBones.TransformFrame();
4064
- this.parseFrame(frameXML, frame);
4065
- frame.visible = !this.getBoolean(frameXML, DBConstValues.A_HIDE, false);
4066
- // NaN:no tween, 10:auto tween, [-1, 0):ease in, 0:line easing, (0, 1]:ease out, (1, 2]:ease in out
4067
- frame.tweenEasing = this.getNumber(frameXML, DBConstValues.A_TWEEN_EASING, dragonBones.AUTO_TWEEN_EASING, dragonBones.NO_TWEEN_EASING);
4068
- frame.tweenRotate = Math.floor(this.getNumber(frameXML, DBConstValues.A_TWEEN_ROTATE, 0, 0));
4069
- frame.tweenScale = this.getBoolean(frameXML, DBConstValues.A_TWEEN_SCALE, true);
4070
- frame.displayIndex = this.getNumber(frameXML, DBConstValues.A_DISPLAY_INDEX, 0, 0);
4071
- frame.zOrder = this.getNumber(frameXML, DBConstValues.A_Z_ORDER, 0, 0);
4072
- var transformXML = frameXML[DBConstValues.TRANSFORM];
4073
- if (transformXML) {
4074
- this.parseTransform(transformXML, frame.global);
4075
- this.parsePivot(transformXML, frame.pivot);
4076
- }
4077
- // copy
4078
- frame.transform.copy(frame.global);
4079
- frame.scaleOffset.x = this.getNumber(frameXML, DBConstValues.A_SCALE_X_OFFSET, 0, 0);
4080
- frame.scaleOffset.y = this.getNumber(frameXML, DBConstValues.A_SCALE_Y_OFFSET, 0, 0);
4081
- var colorTransformXML = frameXML[DBConstValues.COLOR_TRANSFORM];
4082
- if (colorTransformXML) {
4083
- frame.color = new dragonBones.ColorTransform();
4084
- this.parseColorTransform(colorTransformXML, frame.color);
4085
- }
4086
- return frame;
4087
- },
4088
- parseRectangleData: function (rectangleXML) {
4089
- /*RectangleData *rectangleData = new RectangleData();
4090
- rectangleData.name = rectangleXML.Attribute(DBConstValues.A_NAME);
4091
- rectangleData.width = rectangleXML.FloatAttribute(DBConstValues.A_WIDTH);
4092
- rectangleData.height = rectangleXML.FloatAttribute(DBConstValues.A_HEIGHT);
4093
-
4094
- const XMLElement *transformXML = rectangleXML.FirstChildElement(DBConstValues.TRANSFORM);
4095
- if (transformXML)
4096
- {
4097
- parseTransform(*transformXML, rectangleData.transform);
4098
- parsePivot(*transformXML, rectangleData.pivot);
4099
- }
4100
-
4101
- return rectangleData;*/
4102
- return null;
4103
- },
4104
- parseEllipseData: function (ellipseXML) {
4105
- /*EllipseData *ellipseData = new EllipseData();
4106
- ellipseData.name = ellipseXML.Attribute(DBConstValues.A_NAME);
4107
- ellipseData.width = ellipseXML.FloatAttribute(DBConstValues.A_WIDTH);
4108
- ellipseData.height = ellipseXML.FloatAttribute(DBConstValues.A_HEIGHT);
4109
-
4110
- const XMLElement *transformXML = ellipseXML.FirstChildElement(DBConstValues.TRANSFORM);
4111
- if (transformXML)
4112
- {
4113
- parseTransform(*transformXML, ellipseData.transform);
4114
- parsePivot(*transformXML, ellipseData.pivot);
4115
- }
4116
-
4117
- return ellipseData;*/
4118
- return null;
4119
- },
4120
- parseTimeline: function (timelineXML, timeline) {
4121
- var position = 0;
4122
- var frame = null;
4123
- for (var i = 0, l = timeline.frameList.length; i < l; ++i) {
4124
- frame = timeline.frameList[i];
4125
- frame.position = position;
4126
- position += frame.duration;
4127
- }
4128
- if (frame) {
4129
- frame.duration = timeline.duration - frame.position;
4130
- }
4131
- },
4132
- parseFrame: function (frameXML, frame) {
4133
- frame.duration = Math.round(this.getNumber(frameXML, DBConstValues.A_DURATION, 1, 1) * 1000 / this._frameRate);
4134
- frame.action = frameXML[DBConstValues.A_ACTION];
4135
- frame.event = frameXML[DBConstValues.A_EVENT];
4136
- frame.sound = frameXML[DBConstValues.A_SOUND];
4137
- },
4138
- parseTransform: function (transformXML, transform) {
4139
- transform.x = this.getNumber(transformXML, DBConstValues.A_X, 0, 0) / this._armatureScale;
4140
- transform.y = this.getNumber(transformXML, DBConstValues.A_Y, 0, 0) / this._armatureScale;
4141
- transform.skewX = this.getNumber(transformXML, DBConstValues.A_SKEW_X, 0, 0) * dragonBones.ANGLE_TO_RADIAN;
4142
- transform.skewY = this.getNumber(transformXML, DBConstValues.A_SKEW_Y, 0, 0) * dragonBones.ANGLE_TO_RADIAN;
4143
- transform.scaleX = this.getNumber(transformXML, DBConstValues.A_SCALE_X, 1, 0);
4144
- transform.scaleY = this.getNumber(transformXML, DBConstValues.A_SCALE_Y, 1, 0);
4145
- },
4146
- parsePivot: function (transformXML, pivot) {
4147
- pivot.x = this.getNumber(transformXML, DBConstValues.A_PIVOT_X, 0, 0) / this._armatureScale;
4148
- pivot.y = this.getNumber(transformXML, DBConstValues.A_PIVOT_Y, 0, 0) / this._armatureScale;
4149
- },
4150
- parseColorTransform: function (colorTransformXML, colorTransform) {
4151
- colorTransform.alphaOffset = this.getNumber(colorTransformXML, DBConstValues.A_ALPHA_OFFSET, 0, 0);
4152
- colorTransform.redOffset = this.getNumber(colorTransformXML, DBConstValues.A_RED_OFFSET, 0, 0);
4153
- colorTransform.greenOffset = this.getNumber(colorTransformXML, DBConstValues.A_GREEN_OFFSET, 0, 0);
4154
- colorTransform.blueOffset = this.getNumber(colorTransformXML, DBConstValues.A_BLUE_OFFSET, 0, 0);
4155
- colorTransform.alphaMultiplier = this.getNumber(colorTransformXML, DBConstValues.A_ALPHA_MULTIPLIER, 100, 100) * 0.01;
4156
- colorTransform.redMultiplier = this.getNumber(colorTransformXML, DBConstValues.A_RED_MULTIPLIER, 100, 100) * 0.01;
4157
- colorTransform.greenMultiplier = this.getNumber(colorTransformXML, DBConstValues.A_GREEN_MULTIPLIER, 100, 100) * 0.01;
4158
- colorTransform.blueMultiplier = this.getNumber(colorTransformXML, DBConstValues.A_BLUE_MULTIPLIER, 100, 100) * 0.01;
4159
- },
4160
- parseTextData: function (textXML, textData) {
4161
- /*textData.bold = getBoolean(textXML, ConstValues::A_BOLD.c_str(), false);
4162
- textData.italic = getBoolean(textXML, ConstValues::A_ITALIC.c_str(), false);
4163
-
4164
- textData.size = textXML.UnsignedAttribute(ConstValues::A_SIZE.c_str());
4165
-
4166
- const XMLElement *colorXML = textXML.FirstChildElement(ConstValues::COLOR.c_str());
4167
- if (colorXML)
4168
- {
4169
- textData.alpha = colorXML.UnsignedAttribute(ConstValues::A_ALPHA.c_str());
4170
- textData.red = colorXML.UnsignedAttribute(ConstValues::A_RED.c_str());
4171
- textData.green = colorXML.UnsignedAttribute(ConstValues::A_GREEN.c_str());
4172
- textData.blue = colorXML.UnsignedAttribute(ConstValues::A_BLUE.c_str());
4173
- }
4174
-
4175
- textData.width = textXML.UnsignedAttribute(ConstValues::A_WIDTH.c_str());
4176
- textData.height = textXML.UnsignedAttribute(ConstValues::A_HEIGHT.c_str());
4177
-
4178
- textData.face = textXML.Attribute(ConstValues::A_FACE.c_str());
4179
- textData.text = textXML.Attribute(ConstValues::A_TEXT.c_str());
4180
-
4181
- textData.alignH = getAlignHType(textXML.Attribute(ConstValues::A_ALIGN_H.c_str()));
4182
- textData.alignV = getAlignVType(textXML.Attribute(ConstValues::A_ALIGN_V.c_str()));*/
4183
- },
4184
- getBoolean: function (data, key, defaultValue) {
4185
- if (data && key in data) {
4186
- switch (String(data[key])) {
4187
- case '0':
4188
- case 'NaN':
4189
- case '':
4190
- case 'false':
4191
- case 'null':
4192
- case 'undefined':
4193
- return false;
4194
- case '1':
4195
- case 'true':
4196
- default:
4197
- return true;
4198
- }
4199
- }
4200
- return defaultValue;
4201
- },
4202
- getNumber: function (data, key, defaultValue, nanValue) {
4203
- if (nanValue === undefined) {
4204
- nanValue = NaN;
4205
- }
4206
- if (data && key in data) {
4207
- switch (String(data[key])) {
4208
- case 'NaN':
4209
- case '':
4210
- case 'false':
4211
- case 'null':
4212
- case 'undefined':
4213
- return nanValue;
4214
- default:
4215
- return Number(data[key]);
4216
- }
4217
- }
4218
- return defaultValue;
4219
- }
4220
- });
4221
- /*----------------------------------------------------------------------parsers部分---------------------------------------------------------------*/
4222
- /*----------------------------------------------------------------------textures部分---------------------------------------------------------------*/
4223
- dragonBones.TextureAtlasData = cc.Class.extend({
4224
- autoSearch: false,
4225
- name: null,
4226
- imagePath: null,
4227
- textureDataList: null,
4228
- ctor: function () {
4229
- this.textureDataList = [];
4230
- },
4231
- dispose: function () {
4232
- for (var i = 0, l = this.textureDataList.length; i < l; ++i) {
4233
- this.textureDataList[i].dispose();
4234
- }
4235
- this.textureDataList.length = 0;
4236
- },
4237
- getTextureData: function (textureName) {
4238
- for (var i = 0, l = this.textureDataList.length; i < l; ++i) {
4239
- if (this.textureDataList[i].name == textureName) {
4240
- return this.textureDataList[i];
4241
- }
4242
- }
4243
- return null;
4244
- }
4245
- });
4246
- dragonBones.TextureData = cc.Class.extend({
4247
- rotated: false,
4248
- name: null,
4249
- region: null,
4250
- frame: null,
4251
- ctor: function () {
4252
- this.region = new dragonBones.Rectangle();
4253
- },
4254
- dispose: function () {
4255
- this.name = null;
4256
- this.region = null;
4257
- this.frame = null;
4258
- }
4259
- });
4260
- /*----------------------------------------------------------------------textures部分---------------------------------------------------------------*/
4261
- /*----------------------------------------------------------------------utils部分---------------------------------------------------------------*/
4262
- dragonBones.utils = dragonBones.utils || {};
4263
- var DBUtils = dragonBones.utils;
4264
- DBUtils.TransformUtil = {
4265
- DOUBLE_PI: Math.PI * 2,
4266
- formatRadian: function (radian) {
4267
- radian %= this.DOUBLE_PI;
4268
- if (radian > Math.PI) {
4269
- radian -= this.DOUBLE_PI;
4270
- }
4271
- if (radian < -Math.PI) {
4272
- radian += this.DOUBLE_PI;
4273
- }
4274
- return radian;
4275
- },
4276
- getEaseValue: function (value, easing) {
4277
- var valueEase = 1;
4278
- if (easing > 1) { // ease in out
4279
- valueEase = 0.5 * (1 - Math.cos(value * Math.PI));
4280
- easing -= 1;
4281
- }
4282
- else if (easing > 0) { // ease out
4283
- valueEase = 1 - Math.pow(1 - value, 2);
4284
- }
4285
- else if (easing < 0) { // ease in
4286
- easing *= -1;
4287
- valueEase = Math.pow(value, 2);
4288
- }
4289
- return (valueEase - value) * easing + value;
4290
- }
4291
- };
4292
- /*----------------------------------------------------------------------utils部分---------------------------------------------------------------*/
4293
- /*----------------------------------------------------------------------render部分---------------------------------------------------------------*/
4294
- dragonBones.DBCCArmature = dragonBones.Armature.extend({
4295
- _armatureNode: null,
4296
- ctor: function (armatureData, animation, eventDispatcher, display) {
4297
- dragonBones.Armature.prototype.ctor.call(this, armatureData, animation, eventDispatcher, display);
4298
- },
4299
- getCCDisplay: function () {
4300
- return this._display;
4301
- },
4302
- getCCEventDispatcher: function () {
4303
- return this._eventDispatcher.eventDispatcher;
4304
- },
4305
- dispose: function () {
4306
- this._delayDispose = true;
4307
- if (!this._animation || this._lockDispose) {
4308
- return;
4309
- }
4310
- if (this._display) {
4311
- this._display.cleanup();
4312
- this._display.release();
4313
- }
4314
- dragonBones.Armature.prototype.dispose.call(this);
4315
- },
4316
- getBoundingBox: function () {
4317
- var r = this.getCCBoundingBox();
4318
- return new dragonBones.Rectangle(r.origin.x, r.origin.y, r.size.width, r.size.height);
4319
- },
4320
- getCCBoundingBox: function () {
4321
- var minx = 0, miny = 0, maxx = 0, maxy = 0;
4322
- var first = true;
4323
- var i = this._slotList.length;
4324
- var slot;
4325
- var r;
4326
- var rect;
4327
- while (--i >= 0) {
4328
- slot = this._slotList[i];
4329
- if (!slot.getVisible() || !slot.isShowDisplay()) {
4330
- continue;
4331
- }
4332
- r = slot.getBoundingBox();
4333
- if (first) {
4334
- first = false;
4335
- minx = r.x;
4336
- miny = r.y;
4337
- maxx = r.x + r.width;
4338
- maxy = r.y + r.height;
4339
- }
4340
- else {
4341
- minx = r.x < minx ? r.x : minx;
4342
- miny = r.y < miny ? r.y : miny;
4343
- maxx = r.x + r.width > maxx ? r.x + r.width : maxx;
4344
- maxy = r.y + r.height > maxy ? r.y + r.height : maxy;
4345
- }
4346
- }
4347
- rect = cc.rect(minx, miny, maxx - minx, maxy - miny);
4348
- return cc.rectApplyAffineTransform(rect, this.getCCDisplay().getNodeToParentTransform());
4349
- },
4350
- getCCSlot: function (slotName) {
4351
- var slot = this.getSlot(slotName);
4352
- return slot ? slot : null;
4353
- },
4354
- getArmatureNode: function () {
4355
- return this._armatureNode;
4356
- },
4357
- setArmatureNode: function (armatureNode) {
4358
- this._armatureNode = armatureNode;
4359
- },
4360
- sortSlotsByZOrder: function () {
4361
- this._slotList.sort(this.sortSlot);
4362
- var nShowCount = 0;
4363
- var nDisplayChildrenCount = this._display.getChildrenCount();
4364
- var slot;
4365
- var slotDisplayNode;
4366
- for (var i = 0, l = this._slotList.length; i < l; ++i) {
4367
- slot = this._slotList[i];
4368
- if (slot.isShowDisplay()) {
4369
- slotDisplayNode = slot.getDisplay();
4370
- if (slotDisplayNode) {
4371
- slotDisplayNode.setLocalZOrder(nDisplayChildrenCount + nShowCount);
4372
- }
4373
- nShowCount += 1;
4374
- }
4375
- }
4376
- this._slotsZOrderChanged = false;
4377
- }
4378
- });
4379
- dragonBones.DBCCArmatureNode = cc.Node.extend({
4380
- _armature: null,
4381
- _clock: null,
4382
- ctor: function () { },
4383
- getCCSlot: function (slotName) { return this._armature.getCCSlot(slotName); },
4384
- getCCDisplay: function () { return this._armature.getCCDisplay(); },
4385
- getCCEventDispatcher: function () { return this._armature.getCCEventDispatcher(); },
4386
- getBoundingBox: function () { },
4387
- /*static DBCCArmatureNode* create(DBCCArmature *armature);
4388
-
4389
- /**
4390
- * create DDCCArmatureNode with WorldClock
4391
- * @param armature
4392
- * @param clock if null, use WorldClock::getInstance()
4393
- * @return
4394
-
4395
- static DBCCArmatureNode* createWithWorldClock(DBCCArmature *armature, WorldClock *clock);*/
4396
- initWithDBCCArmature: function (armature, clock) { },
4397
- getArmature: function () { return this._armature; },
4398
- getAnimation: function () { return this._armature.getAnimation(); },
4399
- update: function (dt) { },
4400
- advanceTime: function (dt) { }
4401
- });
4402
- dragonBones.DBCCEventDispatcher = cc.Class.extend({
4403
- eventDispatcher: null,
4404
- ctor: function () { },
4405
- dispose: function () {
4406
- if (this.eventDispatcher) {
4407
- //BUG #1事件移除需修改(自己手动移除事件)
4408
- //eventDispatcher.removeAllEventListeners();
4409
- //eventDispatcher.setEnabled(false);
4410
- this.eventDispatcher = null;
4411
- }
4412
- },
4413
- dispatchEvent: function (eventData) {
4414
- if (this.eventDispatcher) {
4415
- this.eventDispatcher.dispatchCustomEvent(eventData.getStringType(), eventData);
4416
- }
4417
- },
4418
- hasEvent: function (eventDataType) {
4419
- return this.eventDispatcher != null; //存在问题
4420
- }
4421
- });
4422
- dragonBones.DBCCFactory = dragonBones.BaseFactory.extend({
4423
- ctor: function () {
4424
- this._super();
4425
- },
4426
- /**
4427
- *
4428
- * @return {dragonBones.Armature}
4429
- */
4430
- buildArmature: function (armatureName, skinName, animationName, dragonBonesName, textureAtlasName) {
4431
- return dragonBones.BaseFactory.prototype.buildArmature.call(this, armatureName, skinName, animationName, dragonBonesName, textureAtlasName);
4432
- },
4433
- loadDragonBonesData: function (dragonBonesFilePath, name) {
4434
- var existDragonBonesData = this.getDragonBonesData(name);
4435
- if (existDragonBonesData) {
4436
- return existDragonBonesData;
4437
- }
4438
- var data = cc.loader.getRes(dragonBonesFilePath);
4439
- // console.log('dragonBonesFilePath', dragonBonesFilePath, data);
4440
- if (data == null) {
4441
- return null;
4442
- }
4443
- // armature scale
4444
- var scale = cc.director.getContentScaleFactor();
4445
- var parser = new dragonBones.ObjectDataParser();
4446
- var dragonBonesData = parser.parseDragonBonesData(data, scale);
4447
- this.addDragonBonesData(dragonBonesData, name);
4448
- return dragonBonesData;
4449
- },
4450
- loadTextureAtlas: function (textureAtlasFile, name) {
4451
- if (name === undefined) {
4452
- name = null;
4453
- }
4454
- var existTextureAtlas = this.getTextureAtlas(name);
4455
- if (existTextureAtlas) {
4456
- this.refreshTextureAtlasTexture(name == null ? existTextureAtlas.textureAtlasData.name : name);
4457
- return existTextureAtlas;
4458
- }
4459
- var data = cc.loader.getRes(textureAtlasFile);
4460
- // console.log('textureAtlasFile', textureAtlasFile, data);
4461
- if (data == null) {
4462
- return null;
4463
- }
4464
- // textureAtlas scale
4465
- var scale = cc.director.getContentScaleFactor();
4466
- var parser = new dragonBones.ObjectDataParser();
4467
- var textureAtlas = new dragonBones.DBCCTextureAtlas();
4468
- textureAtlas.textureAtlasData = parser.parseTextureAtlasData(data, scale);
4469
- var pos = textureAtlasFile.lastIndexOf('/');
4470
- if (-1 != pos) {
4471
- var base_path = textureAtlasFile.substr(0, pos + 1);
4472
- textureAtlas.textureAtlasData.imagePath = base_path + textureAtlas.textureAtlasData.imagePath;
4473
- }
4474
- //
4475
- this.addTextureAtlas(textureAtlas, name);
4476
- this.refreshTextureAtlasTexture(textureAtlas.textureAtlasData.name || name);
4477
- return textureAtlas;
4478
- },
4479
- refreshTextureAtlasTexture: function (name) {
4480
- var textureAtlas;
4481
- for (var key in this._textureAtlasMap) {
4482
- textureAtlas = this._textureAtlasMap[key];
4483
- //textureAtlasData = textureAtlas.textureAtlasData;
4484
- if (key == name) {
4485
- textureAtlas.reloadTexture();
4486
- }
4487
- }
4488
- },
4489
- refreshAllTextureAtlasTexture: function () {
4490
- var textureAtlas;
4491
- for (var key in this._textureAtlasMap) {
4492
- textureAtlas = this._textureAtlasMap[key];
4493
- textureAtlas.reloadTexture();
4494
- }
4495
- },
4496
- hasDragonBones: function (skeletonName, armatureName, animationName) {
4497
- if (armatureName === undefined) {
4498
- armatureName = null;
4499
- }
4500
- if (animationName === undefined) {
4501
- animationName = null;
4502
- }
4503
- var dragonbonesData = this.getDragonBonesData(skeletonName);
4504
- if (!dragonbonesData) {
4505
- return false;
4506
- }
4507
- if (armatureName) {
4508
- var armatureData = dragonbonesData.getArmatureData(armatureName);
4509
- if (!armatureData) {
4510
- return false;
4511
- }
4512
- if (animationName) {
4513
- var animationData = armatureData.getAnimationData(animationName);
4514
- return animationData != null;
4515
- }
4516
- }
4517
- return true;
4518
- },
4519
- generateArmature: function (armatureData) {
4520
- var animation = new dragonBones.Animation();
4521
- // sprite
4522
- var display = new cc.Node();
4523
- display.setCascadeColorEnabled(true);
4524
- display.setCascadeOpacityEnabled(true);
4525
- display.retain();
4526
- // eventDispatcher
4527
- var eventDispatcher = new dragonBones.DBCCEventDispatcher();
4528
- eventDispatcher.eventDispatcher = cc.eventManager;
4529
- // armature
4530
- return new dragonBones.DBCCArmature(armatureData, animation, eventDispatcher, display);
4531
- },
4532
- generateSlot: function (slotData) {
4533
- return new dragonBones.DBCCSlot(slotData);
4534
- },
4535
- generateDisplay: function (textureAtlas, textureData, displayData) {
4536
- // console.log('generateDisplay', textureAtlas, textureData, displayData)
4537
- var dbccTextureAtlas = textureAtlas;
4538
- if (!dbccTextureAtlas || !textureData)
4539
- return null;
4540
- var texture = dbccTextureAtlas.getTexture();
4541
- //cc.assert(texture);
4542
- var x = textureData.region.x;
4543
- var y = textureData.region.y;
4544
- var rotated = textureData.rotated;
4545
- var width = rotated ? textureData.region.height : textureData.region.width;
4546
- var height = rotated ? textureData.region.width : textureData.region.height;
4547
- var rect = cc.rect(x, y, width, height);
4548
- var offset = cc.p(0, 0);
4549
- var originSize = cc.size(width, height);
4550
- if (textureData.frame) {
4551
- var px = -textureData.frame.x;
4552
- var py = -textureData.frame.y;
4553
- originSize.width = textureData.frame.width;
4554
- originSize.height = textureData.frame.height;
4555
- // offset = sprite center - trimed texture center
4556
- var cx1 = px + rect.width / 2;
4557
- var cy1 = originSize.height - py - rect.height / 2;
4558
- var cx2 = originSize.width / 2;
4559
- var cy2 = originSize.height / 2;
4560
- offset.x = cx2 - cx1;
4561
- offset.y = cy2 - cy1;
4562
- }
4563
- // sprite
4564
- var spriteFrame = new cc.SpriteFrame(texture, rect, textureData.rotated, offset, originSize);
4565
- var display = new cc.Sprite(spriteFrame);
4566
- display.setCascadeColorEnabled(true);
4567
- display.setCascadeOpacityEnabled(true);
4568
- display.retain();
4569
- var pivotX = 0;
4570
- var pivotY = 0;
4571
- if (displayData) {
4572
- pivotX = displayData.pivot.x;
4573
- pivotY = displayData.pivot.y;
4574
- }
4575
- display.setAnchorPoint(cc.p(pivotX / originSize.width, 1 - pivotY / originSize.height));
4576
- display.setContentSize(originSize);
4577
- return display;
4578
- }
4579
- });
4580
- dragonBones.DBCCSlot = dragonBones.Slot.extend({
4581
- _nodeDisplay: null,
4582
- ctor: function (slotData) {
4583
- dragonBones.Slot.prototype.ctor.call(this, slotData);
4584
- },
4585
- dispose: function () {
4586
- this.disposeDisplayList();
4587
- dragonBones.Slot.prototype.dispose.call(this);
4588
- this._nodeDisplay = null;
4589
- },
4590
- getCCDisplay: function () {
4591
- return this._nodeDisplay;
4592
- },
4593
- getCCChildArmature: function () {
4594
- return this._childArmature;
4595
- },
4596
- getGlobalPosition: function () {
4597
- var _a, _b;
4598
- return cc.p((_a = this.global) === null || _a === void 0 ? void 0 : _a.x, (_b = this.global) === null || _b === void 0 ? void 0 : _b.y);
4599
- },
4600
- setDisplayImage: function (display, disposeExisting) {
4601
- if (disposeExisting === undefined) {
4602
- disposeExisting = true;
4603
- }
4604
- dragonBones.Slot.prototype.setDisplay.call(this, display, dragonBones.DisplayType.DT_IMAGE, disposeExisting);
4605
- },
4606
- getBoundingBox: function () {
4607
- if (this._displayIndex < 0) {
4608
- return new dragonBones.Rectangle();
4609
- }
4610
- if (this._displayList[this._displayIndex] instanceof dragonBones.Armature) {
4611
- return this.getCCChildArmature().getBoundingBox();
4612
- }
4613
- var displayA = this.getCCDisplay();
4614
- if (displayA) {
4615
- var r = displayA.getBoundingBox();
4616
- return new dragonBones.Rectangle(r.origin.x, r.origin.y, r.size.width, r.size.height);
4617
- }
4618
- return new dragonBones.Rectangle();
4619
- },
4620
- updateDisplayColor: function (aOffset, rOffset, gOffset, bOffset, aMultiplier, rMultiplier, gMultiplier, bMultiplier) {
4621
- if (this._nodeDisplay) {
4622
- //record colorTransform
4623
- dragonBones.Slot.prototype.updateDisplayColor.call(this, aOffset, rOffset, gOffset, bOffset, aMultiplier, rMultiplier, gMultiplier, bMultiplier);
4624
- // cocos2dx does not support offset of color.
4625
- this._nodeDisplay.setOpacity(aMultiplier * 255);
4626
- this._nodeDisplay.setColor(cc.color(rMultiplier * 255, gMultiplier * 255, bMultiplier * 255, null));
4627
- }
4628
- },
4629
- getDisplayZIndex: function () {
4630
- if (this._nodeDisplay) {
4631
- return this._nodeDisplay.getLocalZOrder();
4632
- }
4633
- return -1;
4634
- },
4635
- addDisplayToContainer: function (container, zIndex) {
4636
- if (this._nodeDisplay && container) {
4637
- this.removeDisplayFromContainer();
4638
- if (container._displayBatchNode == null) {
4639
- container._displayBatchNode = cc.SpriteBatchNode.create(this._nodeDisplay.texture, cc.SpriteBatchNode.DEFAULT_CAPACITY);
4640
- container._displayBatchNode.name = 'batchNode';
4641
- // console.log('container._displayBatchNode', container._displayBatchNode)
4642
- container._display.addChild(container._displayBatchNode);
4643
- }
4644
- var sprite = new cc.Sprite(this._nodeDisplay.texture, this._nodeDisplay._rect);
4645
- if (zIndex < 0) {
4646
- // console.log('addDisplayTo', this._nodeDisplay);
4647
- // this._nodeDisplay = sprite
4648
- container._displayBatchNode.addChild(this._nodeDisplay, container._displayBatchNode.getChildrenCount());
4649
- container._displayBatchNode.addChild(sprite, container._displayBatchNode.getChildrenCount());
4650
- }
4651
- else {
4652
- container._displayBatchNode.addChild(this._nodeDisplay, zIndex);
4653
- }
4654
- }
4655
- },
4656
- removeDisplayFromContainer: function () {
4657
- if (this._nodeDisplay && this._nodeDisplay.getParent()) {
4658
- this._nodeDisplay.removeFromParent(false);
4659
- }
4660
- },
4661
- disposeDisplay: function () {
4662
- if (this._nodeDisplay) {
4663
- this._nodeDisplay.cleanup();
4664
- this._nodeDisplay.release();
4665
- this._nodeDisplay = null;
4666
- }
4667
- },
4668
- disposeDisplayList: function () {
4669
- var releasedNodeList = [];
4670
- var displayA;
4671
- var armature;
4672
- for (var i = 0, l = this._displayList.length; i < l; ++i) {
4673
- displayA = this._displayList[i];
4674
- if (displayA instanceof dragonBones.Armature) {
4675
- displayA.dispose();
4676
- }
4677
- else {
4678
- if (displayA && releasedNodeList.indexOf(displayA) < 0) {
4679
- displayA.cleanup();
4680
- displayA.release();
4681
- releasedNodeList.push(displayA);
4682
- }
4683
- }
4684
- }
4685
- releasedNodeList.length = 0;
4686
- },
4687
- updateDisplay: function (display) {
4688
- this._nodeDisplay = display;
4689
- },
4690
- updateDisplayBlendMode: function (blendMode) {
4691
- var spriteDisplay = this._nodeDisplay;
4692
- if (spriteDisplay) {
4693
- switch (blendMode) {
4694
- case dragonBones.BlendMode.BM_ADD:
4695
- {
4696
- var texture = spriteDisplay.getTexture();
4697
- if (texture && texture.hasPremultipliedAlpha()) {
4698
- spriteDisplay.setBlendFunc(new cc.BlendFunc(cc.ONE, cc.ONE));
4699
- }
4700
- else {
4701
- spriteDisplay.setBlendFunc(new cc.BlendFunc(cc.SRC_ALPHA, cc.ONE));
4702
- }
4703
- break;
4704
- }
4705
- case dragonBones.BlendMode.BM_ALPHA:
4706
- break;
4707
- case dragonBones.BlendMode.BM_DARKEN:
4708
- break;
4709
- case dragonBones.BlendMode.BM_DIFFERENCE:
4710
- break;
4711
- case dragonBones.BlendMode.BM_ERASE:
4712
- break;
4713
- case dragonBones.BlendMode.BM_HARDLIGHT:
4714
- break;
4715
- case dragonBones.BlendMode.BM_INVERT:
4716
- break;
4717
- case dragonBones.BlendMode.BM_LAYER:
4718
- break;
4719
- case dragonBones.BlendMode.BM_LIGHTEN:
4720
- break;
4721
- case dragonBones.BlendMode.BM_MULTIPLY:
4722
- break;
4723
- case dragonBones.BlendMode.BM_NORMAL:
4724
- break;
4725
- case dragonBones.BlendMode.BM_OVERLAY:
4726
- break;
4727
- case dragonBones.BlendMode.BM_SCREEN:
4728
- break;
4729
- case dragonBones.BlendMode.BM_SHADER:
4730
- break;
4731
- case dragonBones.BlendMode.BM_SUBTRACT:
4732
- break;
4733
- default:
4734
- break;
4735
- }
4736
- if (this._childArmature) {
4737
- var slot = void 0;
4738
- var list = this._childArmature.getSlots();
4739
- for (var i = 0, l = list.length; i < l; ++i) {
4740
- slot = list[i];
4741
- slot._blendMode = blendMode;
4742
- slot.updateDisplayBlendMode(blendMode);
4743
- }
4744
- }
4745
- }
4746
- },
4747
- updateDisplayVisible: function (visible) {
4748
- if (this._nodeDisplay && this._parent) {
4749
- this._nodeDisplay.setVisible(this._parent.getVisible() && this._visible && visible);
4750
- }
4751
- },
4752
- updateDisplayTransform: function () {
4753
- if (this._nodeDisplay) {
4754
- this._nodeDisplay.setScaleX(this.global.scaleX);
4755
- this._nodeDisplay.setScaleY(this.global.scaleY);
4756
- this._nodeDisplay.setRotationX(this.global.skewX * dragonBones.RADIAN_TO_ANGLE);
4757
- this._nodeDisplay.setRotationY(this.global.skewY * dragonBones.RADIAN_TO_ANGLE);
4758
- this._nodeDisplay.setPosition(this.global.x, -this.global.y);
4759
- }
4760
- }
4761
- });
4762
- dragonBones.DBCCTextureAtlas = cc.Class.extend({
4763
- textureAtlasData: null,
4764
- ctor: function () { },
4765
- dispose: function () {
4766
- if (this.textureAtlasData) {
4767
- this.textureAtlasData.dispose();
4768
- this.textureAtlasData = null;
4769
- }
4770
- },
4771
- getTexture: function () {
4772
- // console.log('textureAtlasData', this.textureAtlasData, cc.textureCache)
4773
- if (!this.textureAtlasData)
4774
- return null;
4775
- var textureCache = cc.textureCache;
4776
- var texture = textureCache.getTextureForKey(this.textureAtlasData.imagePath);
4777
- if (!texture) {
4778
- texture = textureCache.addImage(this.textureAtlasData.imagePath);
4779
- }
4780
- return texture;
4781
- },
4782
- reloadTexture: function () {
4783
- if (!this.textureAtlasData)
4784
- return null;
4785
- var textureCache = cc.textureCache;
4786
- return textureCache.addImage(this.textureAtlasData.imagePath);
4787
- }
4788
- });