Skip to content

Commit

Permalink
Improve the test case of dragonbones.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbin committed Sep 22, 2016
1 parent d34293c commit b0edc66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
14 changes: 14 additions & 0 deletions assets/cases/dragonbones/DragonBones.fire
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@
"_N$dragonAtlasAsset": {
"__uuid__": "2349e917-5cb4-44bd-98ae-81fbad154586"
},
"_N$_defaultArmatureIndex": 3,
"_N$_animationIndex": 0,
"_N$timeScale": 1,
"_N$debugBones": false
},
Expand Down Expand Up @@ -611,6 +613,7 @@
"a": 255
},
"duration": 0.1,
"zoomScale": 0.1,
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
Expand All @@ -619,6 +622,7 @@
},
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": true,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
Expand Down Expand Up @@ -824,6 +828,7 @@
"a": 255
},
"duration": 0.1,
"zoomScale": 0.1,
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
Expand All @@ -832,6 +837,7 @@
},
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": true,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
Expand Down Expand Up @@ -1037,6 +1043,7 @@
"a": 255
},
"duration": 0.1,
"zoomScale": 0.1,
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
Expand All @@ -1045,6 +1052,7 @@
},
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": true,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
Expand Down Expand Up @@ -1191,6 +1199,7 @@
"a": 255
},
"duration": 0.1,
"zoomScale": 0.1,
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
Expand All @@ -1199,6 +1208,7 @@
},
"clickEvents": [],
"_N$interactable": true,
"_N$enableAutoGrayEffect": true,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
Expand Down Expand Up @@ -1404,6 +1414,7 @@
"a": 255
},
"duration": 0.1,
"zoomScale": 0.1,
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
Expand All @@ -1416,6 +1427,7 @@
}
],
"_N$interactable": true,
"_N$enableAutoGrayEffect": true,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
Expand Down Expand Up @@ -1629,6 +1641,7 @@
"a": 255
},
"duration": 0.1,
"zoomScale": 0.1,
"pressedSprite": {
"__uuid__": "e9ec654c-97a2-4787-9325-e6a10375219a"
},
Expand All @@ -1641,6 +1654,7 @@
}
],
"_N$interactable": true,
"_N$enableAutoGrayEffect": true,
"_N$normalColor": {
"__type__": "cc.Color",
"r": 255,
Expand Down
28 changes: 9 additions & 19 deletions assets/cases/dragonbones/DragonBonesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ cc.Class({
_aimState : null,
_walkState : null,
_attackState : null,
_target : {
default: cc.p(0, 0),
type: cc.Vec2
}
_target : cc.p(0, 0),
},

// use this for initialization
Expand Down Expand Up @@ -153,13 +150,6 @@ cc.Class({
this._keyHandler(keyCode, false);
},
}, this.node);

cc.eventManager.addListener({
event: cc.EventListener.MOUSE,
onMouseDown : this._onMouseDown,
onMouseUp : this._onMouseUp,
onMouseMove : this._onMouseMove
}, this.node);
},

_keyHandler: function(keyCode, isDown) {
Expand Down Expand Up @@ -326,10 +316,10 @@ cc.Class({

_frameEventHandler : function (event) {
if (event.detail.name === "onFire") {
const firePointBone = event.detail.armature.getBone("firePoint");
var firePointBone = event.detail.armature.getBone("firePoint");
var localPoint = cc.p(firePointBone.global.x, firePointBone.global.y);

const display = event.detail.armature.display;
var display = event.detail.armature.display;
var globalPoint = display.convertToWorldSpace(localPoint);

this._fire(globalPoint);
Expand All @@ -342,7 +332,7 @@ cc.Class({

var armature = this._armatureDisplay.buildArmature("bullet_01");
var effect = this._armatureDisplay.buildArmature("fireEffect_01");
const radian = this._faceDir < 0 ? Math.PI - this._aimRadian : this._aimRadian;
var radian = this._faceDir < 0 ? Math.PI - this._aimRadian : this._aimRadian;
var bullet = new DragonBullet();
bullet.init(this.node.parent._sgNode, armature, effect, radian + Math.random() * 0.02 - 0.01, 40, firePoint);
this.addBullet(bullet);
Expand Down Expand Up @@ -430,7 +420,7 @@ cc.Class({
}
}

const aimOffsetY = this._armature.getBone("chest").global.y * this.node.scaleY;
var aimOffsetY = this._armature.getBone("chest").global.y * this.node.scaleY;

if (this._faceDir > 0) {
this._aimRadian = Math.atan2(-(this._target.y - this.node.y + aimOffsetY), this._target.x - this.node.x);
Expand All @@ -455,12 +445,12 @@ cc.Class({
if (this._aimDir >= 0) {
this._aimState = this._armature.animation.fadeIn(
"aimUp", 0, 1,
0, AIM_ANIMATION_GROUP, 2 //dragonBones.AnimationFadeOutMode.SameGroup
0, AIM_ANIMATION_GROUP, dragonBones.AnimationFadeOutMode.SameGroup
);
} else {
this._aimState = this._armature.animation.fadeIn(
"aimDown", 0, 1,
0, AIM_ANIMATION_GROUP, 2 //dragonBones.AnimationFadeOutMode.SameGroup
0, AIM_ANIMATION_GROUP, dragonBones.AnimationFadeOutMode.SameGroup
);
}

Expand All @@ -484,7 +474,7 @@ cc.Class({
// Animation mixing.
this._attackState = this._armature.animation.fadeIn(
"attack_01", -1, -1,
0, ATTACK_ANIMATION_GROUP, 2 //dragonBones.AnimationFadeOutMode.SameGroup
0, ATTACK_ANIMATION_GROUP, dragonBones.AnimationFadeOutMode.SameGroup
);

this._attackState.autoFadeOutTime = this._attackState.fadeTotalTime;
Expand Down Expand Up @@ -515,7 +505,7 @@ var DragonBullet = cc.Class({

if (effect) {
this._effect = effect;
const effectDisplay = this._effect.display;
var effectDisplay = this._effect.display;
effectDisplay.rotation = radian * dragonBones.DragonBones.RADIAN_TO_ANGLE;
effectDisplay.setPosition(thePos);
effectDisplay.scaleX = 1 + Math.random() * 1;
Expand Down

0 comments on commit b0edc66

Please sign in to comment.