2013-06-06 12:02:54 +08:00
|
|
|
#include "ArmatureScene.h"
|
|
|
|
#include "../../testResource.h"
|
|
|
|
|
|
|
|
using namespace cocos2d;
|
2013-06-20 13:48:43 +08:00
|
|
|
using namespace cocos2d::extension::armature;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* NextTest();
|
|
|
|
Layer* BackTest();
|
|
|
|
Layer* RestartTest();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
static int s_nActionIdx = -1;
|
|
|
|
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer *CreateLayer(int index)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer *layer = NULL;
|
2013-06-06 12:02:54 +08:00
|
|
|
switch(index)
|
|
|
|
{
|
|
|
|
case TEST_DRAGON_BONES_2_0:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestDragonBones20(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
case TEST_COCOSTUDIO_WITH_SKELETON:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestCSWithSkeleton(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
case TEST_COCOSTUDIO_WITHOUT_SKELETON:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestCSWithoutSkeleton(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
case TEST_PERFORMANCE:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestPerformance(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
case TEST_CHANGE_ZORDER:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestChangeZorder(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
case TEST_ANIMATION_EVENT:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestAnimationEvent(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
case TEST_PARTICLE_DISPLAY:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestParticleDisplay(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
case TEST_USE_DIFFERENT_PICTURE:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestUseMutiplePicture(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
case TEST_BOX2D_DETECTOR:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestBox2DDetector(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
case TEST_BOUDINGBOX:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestBoundingBox(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
case TEST_ANCHORPOINT:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestAnchorPoint(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
case TEST_ARMATURE_NESTING:
|
2013-07-23 08:25:44 +08:00
|
|
|
layer = new TestArmatureNesting(); break;
|
2013-06-06 12:02:54 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* NextTest()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
++s_nActionIdx;
|
|
|
|
s_nActionIdx = s_nActionIdx % TEST_LAYER_COUNT;
|
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer* layer = CreateLayer(s_nActionIdx);
|
|
|
|
layer->autorelease();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* BackTest()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
--s_nActionIdx;
|
|
|
|
if( s_nActionIdx < 0 )
|
|
|
|
s_nActionIdx += TEST_LAYER_COUNT;
|
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer* layer = CreateLayer(s_nActionIdx);
|
|
|
|
layer->autorelease();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* RestartTest()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer* layer = CreateLayer(s_nActionIdx);
|
|
|
|
layer->autorelease();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ArmatureTestScene::ArmatureTestScene(bool bPortrait)
|
|
|
|
{
|
|
|
|
TestScene::init();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite *bg = Sprite::create("armature/bg.jpg");
|
2013-06-06 12:02:54 +08:00
|
|
|
bg->setPosition(VisibleRect::center());
|
|
|
|
|
|
|
|
float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width;
|
|
|
|
float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height;
|
|
|
|
|
|
|
|
bg->setScaleX(scaleX);
|
|
|
|
bg->setScaleY(scaleY);
|
|
|
|
|
|
|
|
addChild(bg);
|
|
|
|
}
|
|
|
|
void ArmatureTestScene::runThisTest()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/TestBone0.png", "armature/TestBone0.plist", "armature/TestBone.json");
|
|
|
|
ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Cowboy0.png", "armature/Cowboy0.plist", "armature/Cowboy.json");
|
|
|
|
ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml");
|
|
|
|
ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml");
|
|
|
|
ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml");
|
|
|
|
ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml");
|
|
|
|
ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml");
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
s_nActionIdx = -1;
|
|
|
|
addChild(NextTest());
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-20 14:17:10 +08:00
|
|
|
void ArmatureTestScene::MainMenuCallback(Object* pSender)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-08 22:08:22 +08:00
|
|
|
removeAllChildren();
|
2013-06-20 14:17:10 +08:00
|
|
|
ArmatureDataManager::sharedArmatureDataManager()->purgeArmatureSystem();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ArmatureTestLayer::onEnter()
|
|
|
|
{
|
2013-06-08 17:11:11 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
// add title and subtitle
|
|
|
|
std::string str = title();
|
|
|
|
const char * pTitle = str.c_str();
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF* label = LabelTTF::create(pTitle, "Arial", 18);
|
2013-07-05 16:49:22 +08:00
|
|
|
label->setColor(Color3B(0, 0, 0));
|
2013-06-06 12:02:54 +08:00
|
|
|
addChild(label, 1, 10000);
|
2013-07-12 14:11:55 +08:00
|
|
|
label->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 30) );
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
std::string strSubtitle = subtitle();
|
|
|
|
if( ! strSubtitle.empty() )
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF* l = LabelTTF::create(strSubtitle.c_str(), "Arial", 18);
|
2013-07-05 16:49:22 +08:00
|
|
|
l->setColor(Color3B(0, 0, 0));
|
2013-06-06 12:02:54 +08:00
|
|
|
addChild(l, 1, 10001);
|
2013-07-12 14:11:55 +08:00
|
|
|
l->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 60) );
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// add menu
|
2013-07-24 06:20:22 +08:00
|
|
|
MenuItemImage *item1 = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(ArmatureTestLayer::backCallback,this));
|
|
|
|
MenuItemImage *item2 = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(ArmatureTestLayer::restartCallback, this));
|
|
|
|
MenuItemImage *item3 = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(ArmatureTestLayer::nextCallback, this));
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Menu *menu = Menu::create(item1, item2, item3, NULL);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-07-12 14:47:36 +08:00
|
|
|
menu->setPosition(Point::ZERO);
|
2013-07-12 14:11:55 +08:00
|
|
|
item1->setPosition(Point(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item2->setPosition(Point(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item3->setPosition(Point(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
addChild(menu, 100);
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
setShaderProgram(ShaderCache::getInstance()->programForKey(kShader_PositionTextureColor));
|
2013-06-08 17:11:11 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
void ArmatureTestLayer::onExit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ArmatureTestLayer::title()
|
|
|
|
{
|
|
|
|
return "CSArmature Test Bed";
|
|
|
|
}
|
|
|
|
std::string ArmatureTestLayer::subtitle()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ArmatureTestLayer::restartCallback(Object* pSender)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new ArmatureTestScene();
|
2013-06-06 12:02:54 +08:00
|
|
|
s->addChild( RestartTest() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2013-06-06 12:02:54 +08:00
|
|
|
s->release();
|
|
|
|
}
|
2013-06-20 14:17:10 +08:00
|
|
|
void ArmatureTestLayer::nextCallback(Object* pSender)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new ArmatureTestScene();
|
2013-06-06 12:02:54 +08:00
|
|
|
s->addChild( NextTest() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2013-06-06 12:02:54 +08:00
|
|
|
s->release();
|
|
|
|
}
|
2013-06-20 14:17:10 +08:00
|
|
|
void ArmatureTestLayer::backCallback(Object* pSender)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* s = new ArmatureTestScene();
|
2013-06-06 12:02:54 +08:00
|
|
|
s->addChild( BackTest() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2013-06-06 12:02:54 +08:00
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
void ArmatureTestLayer::draw()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::draw();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TestDragonBones20::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Armature *armature = NULL;
|
|
|
|
armature = Armature::create("Dragon");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(1);
|
|
|
|
armature->getAnimation()->setAnimationScale(0.4f);
|
|
|
|
armature->setPosition(VisibleRect::center().x, VisibleRect::center().y * 0.3f);
|
2013-06-08 22:08:22 +08:00
|
|
|
armature->setScale(0.6f);
|
2013-06-08 17:11:11 +08:00
|
|
|
addChild(armature);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TestDragonBones20::title()
|
|
|
|
{
|
|
|
|
return "Test Export From DragonBones version 2.0";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TestCSWithSkeleton::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
2013-06-20 14:17:10 +08:00
|
|
|
Armature *armature = NULL;
|
|
|
|
armature = Armature::create("Cowboy");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(0);
|
2013-06-08 17:11:11 +08:00
|
|
|
armature->setScale(0.2f);
|
2013-07-12 14:11:55 +08:00
|
|
|
armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y/*-100*/));
|
2013-06-06 12:02:54 +08:00
|
|
|
addChild(armature);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TestCSWithSkeleton::title()
|
|
|
|
{
|
|
|
|
return "Test Export From CocoStudio With Skeleton Effect";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TestCSWithoutSkeleton::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
2013-06-20 14:17:10 +08:00
|
|
|
Armature *armature = NULL;
|
|
|
|
armature = Armature::create("TestBone");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(0);
|
2013-07-22 14:28:19 +08:00
|
|
|
armature->setAnchorPoint(Point(0.5f, -0.1f));
|
2013-06-08 17:11:11 +08:00
|
|
|
armature->setScale(0.2f);
|
2013-07-12 14:11:55 +08:00
|
|
|
armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y-100));
|
2013-06-06 12:02:54 +08:00
|
|
|
addChild(armature);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TestCSWithoutSkeleton::title()
|
|
|
|
{
|
|
|
|
return "Test Export From CocoStudio Without Skeleton Effect";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TestPerformance::~TestPerformance()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void TestPerformance::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
|
|
|
|
|
|
|
armatureCount = frames = times = lastTimes = 0;
|
|
|
|
generated = false;
|
|
|
|
|
|
|
|
scheduleUpdate();
|
|
|
|
}
|
2013-06-08 17:11:11 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
std::string TestPerformance::title()
|
|
|
|
{
|
|
|
|
return "Test Performance";
|
|
|
|
}
|
|
|
|
std::string TestPerformance::subtitle()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
return "Current Armature Count : ";
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-20 14:17:10 +08:00
|
|
|
void TestPerformance::addArmature(Armature *armature)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-08 12:14:43 +08:00
|
|
|
armatureCount++;
|
|
|
|
addChild(armature, armatureCount);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
void TestPerformance::update(float delta)
|
|
|
|
{
|
|
|
|
frames ++;
|
|
|
|
times += delta;
|
|
|
|
|
|
|
|
if (frames/times > 58)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Armature *armature = NULL;
|
|
|
|
armature = new Armature();
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->init("Knight_f/Knight");
|
|
|
|
armature->getAnimation()->playByIndex(0);
|
|
|
|
armature->setPosition(50 + armatureCount * 2, 150);
|
2013-06-08 22:08:22 +08:00
|
|
|
armature->setScale(0.6f);
|
2013-06-06 12:02:54 +08:00
|
|
|
addArmature(armature);
|
|
|
|
armature->release();
|
|
|
|
|
|
|
|
char pszCount[255];
|
|
|
|
sprintf(pszCount, "%s %i", subtitle().c_str(), armatureCount);
|
2013-06-20 14:17:10 +08:00
|
|
|
LabelTTF *label = (LabelTTF*)getChildByTag(10001);
|
2013-06-06 12:02:54 +08:00
|
|
|
label->setString(pszCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TestChangeZorder::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Armature *armature = NULL;
|
2013-06-06 12:02:54 +08:00
|
|
|
currentTag = -1;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
armature = Armature::create("Knight_f/Knight");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(0);
|
2013-07-12 14:11:55 +08:00
|
|
|
armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y-100));
|
2013-06-08 11:48:45 +08:00
|
|
|
++currentTag;
|
2013-06-08 17:11:11 +08:00
|
|
|
armature->setScale(0.6f);
|
2013-06-08 11:48:45 +08:00
|
|
|
addChild(armature, currentTag, currentTag);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
armature = Armature::create("TestBone");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(0);
|
2013-06-08 17:11:11 +08:00
|
|
|
armature->setScale(0.24f);
|
2013-07-12 14:11:55 +08:00
|
|
|
armature->setPosition(Point(VisibleRect::center().x, VisibleRect::center().y-100));
|
2013-06-08 11:48:45 +08:00
|
|
|
++currentTag;
|
|
|
|
addChild(armature, currentTag, currentTag);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
armature = Armature::create("Dragon");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(0);
|
2013-07-12 14:11:55 +08:00
|
|
|
armature->setPosition(Point(VisibleRect::center().x , VisibleRect::center().y-100));
|
2013-06-08 11:48:45 +08:00
|
|
|
++currentTag;
|
2013-06-08 17:11:11 +08:00
|
|
|
armature->setScale(0.6f);
|
2013-06-08 11:48:45 +08:00
|
|
|
addChild(armature, currentTag, currentTag);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
schedule( schedule_selector(TestChangeZorder::changeZorder), 1);
|
|
|
|
|
|
|
|
currentTag = 0;
|
|
|
|
}
|
|
|
|
std::string TestChangeZorder::title()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
return "Test Change ZOrder Of Different Armature";
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
void TestChangeZorder::changeZorder(float dt)
|
|
|
|
{
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Node *node = getChildByTag(currentTag);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
node->setZOrder(CCRANDOM_0_1() * 3);
|
|
|
|
|
|
|
|
currentTag ++;
|
|
|
|
currentTag = currentTag % 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TestAnimationEvent::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
2013-06-20 14:17:10 +08:00
|
|
|
armature = Armature::create("Cowboy");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->play("Fire");
|
2013-06-08 17:11:11 +08:00
|
|
|
armature->setScaleX(-0.24f);
|
|
|
|
armature->setScaleY(0.24f);
|
2013-07-12 14:11:55 +08:00
|
|
|
armature->setPosition(Point(VisibleRect::left().x + 50, VisibleRect::left().y));
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->MovementEventSignal.connect(this, &TestAnimationEvent::animationEvent);
|
|
|
|
addChild(armature);
|
|
|
|
}
|
|
|
|
std::string TestAnimationEvent::title()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
return "Test Armature Animation Event";
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-20 14:17:10 +08:00
|
|
|
void TestAnimationEvent::animationEvent(Armature *armature, MovementEventType movementType, const char *movementID)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
std::string id = movementID;
|
|
|
|
|
2013-06-07 16:13:08 +08:00
|
|
|
if (movementType == LOOP_COMPLETE)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
if (id.compare("Fire") == 0)
|
|
|
|
{
|
2013-07-12 14:11:55 +08:00
|
|
|
ActionInterval *actionToRight = MoveTo::create(2, Point(VisibleRect::right().x - 50, VisibleRect::right().y));
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->stopAllActions();
|
2013-07-16 03:43:22 +08:00
|
|
|
armature->runAction(Sequence::create(actionToRight, CallFunc::create(CC_CALLBACK_0(TestAnimationEvent::callback1,this)), NULL));
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->play("Walk");
|
|
|
|
}
|
|
|
|
else if (id.compare("FireMax") == 0)
|
|
|
|
{
|
2013-07-12 14:11:55 +08:00
|
|
|
ActionInterval *actionToLeft = MoveTo::create(2, Point(VisibleRect::left().x + 50, VisibleRect::left().y));
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->stopAllActions();
|
2013-07-16 03:43:22 +08:00
|
|
|
armature->runAction(Sequence::create(actionToLeft, CallFunc::create(CC_CALLBACK_0(TestAnimationEvent::callback2,this)), NULL));
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->play("Walk");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void TestAnimationEvent::callback1()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
armature->runAction(ScaleTo::create(0.3f, 0.3f, 0.3f));
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->play("FireMax", 10);
|
|
|
|
}
|
|
|
|
void TestAnimationEvent::callback2()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
armature->runAction(ScaleTo::create(0.3f, -0.3f, 0.3f));
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->play("Fire", 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TestParticleDisplay::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
|
|
|
setTouchEnabled(true);
|
|
|
|
|
|
|
|
animationID = 0;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
armature = Armature::create("robot");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(0);
|
|
|
|
armature->setPosition(VisibleRect::center());
|
2013-06-08 17:11:11 +08:00
|
|
|
armature->setScale(0.48f);
|
2013-06-06 12:02:54 +08:00
|
|
|
addChild(armature);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
ParticleDisplayData displayData;
|
2013-06-06 12:02:54 +08:00
|
|
|
displayData.setParam("Particles/SmallSun.plist");
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Bone *bone = Bone::create("p1");
|
2013-06-06 12:02:54 +08:00
|
|
|
bone->addDisplay(&displayData, 0);
|
|
|
|
bone->changeDisplayByIndex(0, true);
|
|
|
|
bone->setIgnoreMovementBoneData(true);
|
|
|
|
bone->setZOrder(100);
|
2013-06-08 22:08:22 +08:00
|
|
|
bone->setScale(1.2f);
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->addBone(bone, "bady-a3");
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
bone = Bone::create("p2");
|
2013-06-06 12:02:54 +08:00
|
|
|
bone->addDisplay(&displayData, 0);
|
|
|
|
bone->changeDisplayByIndex(0, true);
|
|
|
|
bone->setIgnoreMovementBoneData(true);
|
|
|
|
bone->setZOrder(100);
|
2013-06-08 22:08:22 +08:00
|
|
|
bone->setScale(1.2f);
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->addBone(bone, "bady-a30");
|
|
|
|
}
|
|
|
|
std::string TestParticleDisplay::title()
|
|
|
|
{
|
|
|
|
return "Test Particle Display";
|
|
|
|
}
|
|
|
|
std::string TestParticleDisplay::subtitle()
|
|
|
|
{
|
|
|
|
return "Touch to change animation";
|
|
|
|
}
|
2013-06-20 14:17:10 +08:00
|
|
|
bool TestParticleDisplay::ccTouchBegan(Touch *pTouch, Event *pEvent)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-08 12:14:43 +08:00
|
|
|
++animationID;
|
|
|
|
animationID = animationID % armature->getAnimation()->getMovementCount();
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(animationID);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestParticleDisplay::registerWithTouchDispatcher()
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TestUseMutiplePicture::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
|
|
|
setTouchEnabled(true);
|
|
|
|
|
|
|
|
displayIndex = 0;
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
armature = Armature::create("Knight_f/Knight");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(0);
|
2013-07-12 14:11:55 +08:00
|
|
|
armature->setPosition(Point(VisibleRect::left().x+70, VisibleRect::left().y));
|
2013-06-08 22:08:22 +08:00
|
|
|
armature->setScale(1.2f);
|
2013-06-06 12:02:54 +08:00
|
|
|
addChild(armature);
|
|
|
|
|
2013-06-07 22:56:54 +08:00
|
|
|
std::string weapon[] = {"weapon_f-sword.png", "weapon_f-sword2.png", "weapon_f-sword3.png", "weapon_f-sword4.png", "weapon_f-sword5.png", "weapon_f-knife.png", "weapon_f-hammer.png"};
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
SpriteDisplayData displayData;
|
2013-06-06 12:02:54 +08:00
|
|
|
for (int i = 0; i < 7; i++)
|
|
|
|
{
|
2013-06-07 22:56:54 +08:00
|
|
|
displayData.setParam(weapon[i].c_str());
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getBone("weapon")->addDisplay(&displayData, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::string TestUseMutiplePicture::title()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
return "Test One Armature Use Different Picture";
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
std::string TestUseMutiplePicture::subtitle()
|
|
|
|
{
|
|
|
|
return "weapon and armature are in different picture";
|
|
|
|
}
|
2013-06-20 14:17:10 +08:00
|
|
|
bool TestUseMutiplePicture::ccTouchBegan(Touch *pTouch, Event *pEvent)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-08 11:48:45 +08:00
|
|
|
++displayIndex;
|
|
|
|
displayIndex = (displayIndex) % 6;
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getBone("weapon")->changeDisplayByIndex(displayIndex, true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void TestUseMutiplePicture::registerWithTouchDispatcher()
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TestBox2DDetector::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
|
|
|
|
|
|
|
scheduleUpdate();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
armature = Armature::create("Cowboy");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->play("Fire");
|
|
|
|
armature->getAnimation()->setAnimationScale(0.1f);
|
2013-06-08 17:11:11 +08:00
|
|
|
armature->setScaleX(-0.2f);
|
|
|
|
armature->setScaleY(0.2f);
|
2013-07-12 14:11:55 +08:00
|
|
|
armature->setPosition(Point(VisibleRect::left().x + 70, VisibleRect::left().y));
|
2013-06-06 12:02:54 +08:00
|
|
|
addChild(armature);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
armature2 = Armature::create("Cowboy");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature2->getAnimation()->play("Walk");
|
2013-06-08 17:11:11 +08:00
|
|
|
armature2->setScaleX(-0.2f);
|
|
|
|
armature2->setScaleY(0.2f);
|
2013-07-12 14:11:55 +08:00
|
|
|
armature2->setPosition(Point(VisibleRect::right().x - 30, VisibleRect::left().y));
|
2013-06-06 12:02:54 +08:00
|
|
|
addChild(armature2);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
PhysicsWorld::sharedPhysicsWorld()->BoneColliderSignal.connect(this, &TestBox2DDetector::onHit);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
std::string TestBox2DDetector::title()
|
|
|
|
{
|
|
|
|
return "Test Box2D Detector";
|
|
|
|
}
|
|
|
|
void TestBox2DDetector::draw()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
ccGLEnableVertexAttribs( kVertexAttribFlag_Position );
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
kmGLPushMatrix();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
PhysicsWorld::sharedPhysicsWorld()->drawDebug();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
kmGLPopMatrix();
|
|
|
|
|
|
|
|
}
|
|
|
|
void TestBox2DDetector::update(float delta)
|
|
|
|
{
|
|
|
|
armature2->setVisible(true);
|
2013-06-20 14:17:10 +08:00
|
|
|
PhysicsWorld::sharedPhysicsWorld()->update(delta);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-20 14:17:10 +08:00
|
|
|
void TestBox2DDetector::onHit(Bone *bone, Bone *bone2)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
armature2->setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TestBoundingBox::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
armature = Armature::create("Cowboy");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(0);
|
|
|
|
armature->setPosition(VisibleRect::center());
|
2013-06-08 22:08:22 +08:00
|
|
|
armature->setScale(0.2f);
|
2013-06-06 12:02:54 +08:00
|
|
|
addChild(armature);
|
|
|
|
}
|
|
|
|
std::string TestBoundingBox::title()
|
|
|
|
{
|
|
|
|
return "Test BoundingBox";
|
|
|
|
}
|
|
|
|
void TestBoundingBox::draw()
|
|
|
|
{
|
|
|
|
CC_NODE_DRAW_SETUP();
|
|
|
|
|
2013-07-17 09:16:04 +08:00
|
|
|
rect = RectApplyAffineTransform(armature->getBoundingBox(), armature->getNodeToParentTransform());
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
ccDrawColor4B(100, 100, 100, 255);
|
2013-07-12 14:11:55 +08:00
|
|
|
ccDrawRect(rect.origin, Point(rect.getMaxX(), rect.getMaxY()));
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TestAnchorPoint::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
|
|
|
|
|
|
|
for (int i = 0; i<5; i++)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Armature *armature = Armature::create("Cowboy");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(0);
|
|
|
|
armature->setPosition(VisibleRect::center());
|
2013-06-08 22:08:22 +08:00
|
|
|
armature->setScale(0.2f);
|
2013-06-06 12:02:54 +08:00
|
|
|
addChild(armature, 0, i);
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
getChildByTag(0)->setAnchorPoint(Point(0,0));
|
|
|
|
getChildByTag(1)->setAnchorPoint(Point(0,1));
|
|
|
|
getChildByTag(2)->setAnchorPoint(Point(1,0));
|
|
|
|
getChildByTag(3)->setAnchorPoint(Point(1,1));
|
|
|
|
getChildByTag(4)->setAnchorPoint(Point(0.5,0.5));
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
std::string TestAnchorPoint::title()
|
|
|
|
{
|
|
|
|
return "Test Set AnchorPoint";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TestArmatureNesting::onEnter()
|
|
|
|
{
|
|
|
|
ArmatureTestLayer::onEnter();
|
|
|
|
setTouchEnabled(true);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
armature = Armature::create("cyborg");
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->playByIndex(1);
|
|
|
|
armature->setPosition(VisibleRect::center());
|
2013-06-08 22:08:22 +08:00
|
|
|
armature->setScale(1.2f);
|
2013-06-06 12:02:54 +08:00
|
|
|
armature->getAnimation()->setAnimationScale(0.4f);
|
|
|
|
addChild(armature);
|
|
|
|
|
|
|
|
weaponIndex = 0;
|
|
|
|
}
|
|
|
|
std::string TestArmatureNesting::title()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
return "Test Armature Nesting";
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-20 14:17:10 +08:00
|
|
|
bool TestArmatureNesting::ccTouchBegan(Touch *pTouch, Event *pEvent)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-08 11:48:45 +08:00
|
|
|
++weaponIndex;
|
|
|
|
weaponIndex = weaponIndex % 4;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
armature->getBone("armInside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex);
|
|
|
|
armature->getBone("armOutside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void TestArmatureNesting::registerWithTouchDispatcher()
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|