Skip to content

Commit 467c645

Browse files
committed
issue #3419 update armatureTest to v2.2.2
1 parent c40c111 commit 467c645

File tree

6 files changed

+1859
-2
lines changed

6 files changed

+1859
-2
lines changed

tests/CocoStudioTest/ArmatureTest/ArmatureTest.js

+219-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ var armatureSceneArr = [
8686
},
8787
function () {
8888
return new TestArmatureNesting2();
89+
},
90+
function(){
91+
return new TestPlaySeveralMovement();
92+
},
93+
function(){
94+
return new TestEasing();
95+
},
96+
function(){
97+
return new TestCalculatedVertex();
8998
}
9099
];
91100

@@ -94,6 +103,7 @@ if (sys.platform === "browser")
94103
armatureSceneArr.push( function () { return new TestColliderDetector();} );
95104
}else{
96105
armatureSceneArr.push( function () { return new TestPerformanceBatchNode();} );
106+
armatureSceneArr.push( function () { return new TestChangeAnimationInternal();} );
97107
}
98108

99109
var nextArmatureTest = function () {
@@ -614,6 +624,7 @@ var TestColliderDetector = ArmatureTestLayer.extend({
614624

615625
onEnter:function () {
616626
this._super();
627+
ccs.ENABLE_PHYSICS_CHIPMUNK_DETECT = true;
617628
ccs.ArmatureDataManager.getInstance().addArmatureFileInfo(s_Cowboy_json);
618629

619630
this.armature1 = ccs.Armature.create("Cowboy");
@@ -684,7 +695,7 @@ var TestColliderDetector = ArmatureTestLayer.extend({
684695
* currentFrameIndex is the current index animation played to
685696
* frame event may be delay emit, so originFrameIndex may be different from currentFrameIndex.
686697
*/
687-
var p = this.armature1.getBone("Layer126").getDisplayRenderNode().convertToWorldSpace(cc.p(0, 0));
698+
var p = this.armature1.getBone("Layer126").getDisplayRenderNode().convertToWorldSpaceAR(cc.p(0, 0));
688699
this.bullet.setPosition(cc.p(p.x + 60, p.y));
689700
this.bullet.stopAllActions();
690701
this.bullet.runAction(cc.MoveBy.create(1.5, cc.p(800, 0)));
@@ -730,6 +741,113 @@ var TestColliderDetector = ArmatureTestLayer.extend({
730741
}
731742
this.space.removeBody(this.armature2.getBody());
732743
this.space.removeBody(this.bullet.getBody());
744+
ccs.ENABLE_PHYSICS_CHIPMUNK_DETECT = false;
745+
}
746+
});
747+
748+
//------------------------------------------------------------------
749+
//
750+
// TestCalculatedVertex
751+
//
752+
//------------------------------------------------------------------
753+
var TestCalculatedVertex = ArmatureTestLayer.extend({
754+
armature1: null,
755+
armature2: null,
756+
bullet: null,
757+
space: null,
758+
enemyTag: 1,
759+
bulletTag: 2,
760+
761+
onEnter: function () {
762+
this._super();
763+
ccs.ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX = true;
764+
ccs.ArmatureDataManager.getInstance().addArmatureFileInfo(s_Cowboy_json);
765+
766+
this.armature1 = ccs.Armature.create("Cowboy");
767+
this.armature1.getAnimation().play("FireWithoutBullet");
768+
this.armature1.getAnimation().setSpeedScale(0.2);
769+
this.armature1.setScaleX(-0.2);
770+
this.armature1.setScaleY(0.2);
771+
this.armature1.setPosition(cc.p(170, winSize.height / 2));
772+
773+
/*
774+
* Set armature's frame event callback function
775+
* To disconnect this event, just setFrameEventCallFunc(nul, null);
776+
*/
777+
this.armature1.getAnimation().setFrameEventCallFunc(this.onFrameEvent, this);
778+
779+
this.addChild(this.armature1);
780+
781+
this.armature2 = ccs.Armature.create("Cowboy");
782+
this.armature2.getAnimation().play("Walk");
783+
this.armature2.setScaleX(-0.2);
784+
this.armature2.setScaleY(0.2);
785+
this.armature2.setPosition(cc.p(winSize.width - 160, winSize.height / 2));
786+
this.addChild(this.armature2);
787+
788+
this.bullet = cc.Sprite.createWithSpriteFrameName("25.png");
789+
this.addChild(this.bullet);
790+
791+
this.scheduleUpdate();
792+
},
793+
onFrameEvent: function (bone, evt, originFrameIndex, currentFrameIndex) {
794+
cc.log("(" + bone.getName() + ") emit a frame event (" + evt + ") at frame index (" + currentFrameIndex + ").");
795+
/*
796+
* originFrameIndex is the frame index editted in Action Editor
797+
* currentFrameIndex is the current index animation played to
798+
* frame event may be delay emit, so originFrameIndex may be different from currentFrameIndex.
799+
*/
800+
var p = this.armature1.getBone("Layer126").getDisplayRenderNode().convertToWorldSpaceAR(cc.p(0, 0));
801+
this.bullet.setPosition(cc.p(p.x + 60, p.y));
802+
this.bullet.stopAllActions();
803+
this.bullet.runAction(cc.MoveBy.create(1.5, cc.p(800, 0)));
804+
},
805+
806+
update: function (dt) {
807+
this.armature2.setVisible(true);
808+
809+
var rect = this.bullet.getBoundingBox();
810+
811+
// This code is just telling how to get the vertex.
812+
// For a more accurate collider detection, you need to implemente yourself.
813+
814+
var dict = this.armature2.getBoneDic();
815+
for (var key in dict) {
816+
var bone = dict[key];
817+
var bodyList = bone.getColliderBodyList();
818+
for (var i = 0; i < bodyList.length; i++) {
819+
var body = bodyList[i];
820+
var vertexList = body.getCalculatedVertexList();
821+
var minx = miny = maxx = maxy = 0;
822+
for (var j = 0; j < vertexList.length; j++) {
823+
var vertex = vertexList[j];
824+
if (j == 0) {
825+
minx = maxx = vertex.x;
826+
miny = maxy = vertex.y;
827+
} else {
828+
minx = vertex.x < minx ? vertex.x : minx;
829+
miny = vertex.y < miny ? vertex.y : miny;
830+
maxx = vertex.x > maxx ? vertex.x : maxx;
831+
maxy = vertex.y > maxy ? vertex.y : maxy;
832+
}
833+
}
834+
var temp = cc.rect(minx, miny, maxx - minx, maxy - miny);
835+
836+
if (cc.rectContainsRect(temp, rect)) {
837+
this.armature2.setVisible(false);
838+
}
839+
}
840+
}
841+
},
842+
draw: function () {
843+
this.armature2.drawContour();
844+
},
845+
title: function () {
846+
return "Test calculated vertex";
847+
},
848+
onExit:function(){
849+
this._super();
850+
ccs.ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX = false;
733851
}
734852
});
735853

@@ -977,6 +1095,106 @@ var TestArmatureNesting2 = ArmatureTestLayer.extend({
9771095
}
9781096
});
9791097

1098+
//------------------------------------------------------------------
1099+
//
1100+
// TestPlaySeveralMovement
1101+
//
1102+
//------------------------------------------------------------------
1103+
var TestPlaySeveralMovement = ArmatureTestLayer.extend({
1104+
onEnter:function () {
1105+
this._super();
1106+
ccs.ArmatureDataManager.getInstance().addArmatureFileInfo(s_Cowboy_json);
1107+
var armature = ccs.Armature.create("Cowboy");
1108+
armature.getAnimation().play(["Walk", "FireMax", "Fire"],1);
1109+
armature.setScale(0.2);
1110+
armature.setPosition(cc.p(winSize.width / 2, winSize.height / 2));
1111+
this.addChild(armature);
1112+
},
1113+
title:function () {
1114+
return "Test play several movement";
1115+
},
1116+
subtitle:function () {
1117+
return "Movement is played one by one";
1118+
}
1119+
});
1120+
1121+
//------------------------------------------------------------------
1122+
//
1123+
// TestChangeAnimationInternal
1124+
//
1125+
//------------------------------------------------------------------
1126+
var TestChangeAnimationInternal = ArmatureTestLayer.extend({
1127+
onEnter:function () {
1128+
this._super();
1129+
this.setTouchEnabled(true);
1130+
ccs.ArmatureDataManager.getInstance().addArmatureFileInfo(s_Cowboy_json);
1131+
var armature = ccs.Armature.create("Cowboy");
1132+
armature.getAnimation().playByIndex(0);
1133+
armature.setScale(0.2);
1134+
armature.setPosition(cc.p(winSize.width / 2, winSize.height / 2));
1135+
this.addChild(armature);
1136+
},
1137+
title:function () {
1138+
return "Test change animation internal";
1139+
},
1140+
subtitle:function () {
1141+
return "Touch to change animation internal";
1142+
},
1143+
onTouchesBegan: function (touch, event) {
1144+
if (cc.Director.getInstance().getAnimationInterval() == 1 / 30) {
1145+
cc.Director.getInstance().setAnimationInterval(1 / 60);
1146+
}
1147+
else {
1148+
cc.Director.getInstance().setAnimationInterval(1 / 30);
1149+
}
1150+
return false;
1151+
},
1152+
onExit: function () {
1153+
this._super();
1154+
cc.Director.getInstance().setAnimationInterval(1 / 60);
1155+
}
1156+
});
1157+
1158+
//------------------------------------------------------------------
1159+
//
1160+
// TestChangeAnimationInternal
1161+
//
1162+
//------------------------------------------------------------------
1163+
var TestEasing = ArmatureTestLayer.extend({
1164+
animationID: 0,
1165+
armature: null,
1166+
onEnter: function () {
1167+
this._super();
1168+
this.setTouchEnabled(true);
1169+
ccs.ArmatureDataManager.getInstance().addArmatureFileInfo(s_testEasing_json);
1170+
var armature = ccs.Armature.create("testEasing");
1171+
armature.getAnimation().playByIndex(0);
1172+
armature.setScale(0.8);
1173+
armature.setPosition(cc.p(winSize.width / 2, winSize.height / 2));
1174+
this.addChild(armature);
1175+
this.armature = armature;
1176+
this.updateSubTitle();
1177+
},
1178+
title: function () {
1179+
return "Test easing effect";
1180+
},
1181+
subtitle: function () {
1182+
return "Current easing :";
1183+
},
1184+
onTouchesBegan: function (touch, event) {
1185+
this.animationID++;
1186+
this.animationID = this.animationID % this.armature.getAnimation().getMovementCount();
1187+
this.armature.getAnimation().playByIndex(this.animationID);
1188+
1189+
this.updateSubTitle();
1190+
return false;
1191+
},
1192+
updateSubTitle: function () {
1193+
var str = this.subtitle() + this.armature.getAnimation().getCurrentMovementID();
1194+
var label = this.getChildByTag(BASE_TEST_SUBTITLE_TAG);
1195+
label.setString(str);
1196+
}
1197+
});
9801198

9811199
var runArmatureTestScene = function(){
9821200
var pScene = new ArmatureTestScene();

0 commit comments

Comments
 (0)