axmol/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioArmatureTest/ArmatureScene.cpp

1631 lines
47 KiB
C++
Raw Normal View History

2013-06-06 12:02:54 +08:00
#include "ArmatureScene.h"
#include "../../testResource.h"
#include "cocostudio/CocoStudio.h"
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
2013-06-06 12:02:54 +08:00
using namespace cocos2d;
using namespace cocostudio;
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
Layer *NextTest();
Layer *BackTest();
Layer *RestartTest();
2013-06-06 12:02:54 +08:00
static int s_nActionIdx = -1;
Layer *CreateLayer(int index)
2013-06-06 12:02:54 +08:00
{
Layer *pLayer = nullptr;
2013-09-13 18:07:37 +08:00
switch(index)
{
case TEST_ASYNCHRONOUS_LOADING:
pLayer = new (std::nothrow) TestAsynchronousLoading();
2013-09-13 18:07:37 +08:00
break;
case TEST_DIRECT_LOADING:
pLayer = new (std::nothrow) TestDirectLoading();
break;
2013-09-13 18:07:37 +08:00
case TEST_DRAGON_BONES_2_0:
pLayer = new (std::nothrow) TestDragonBones20();
2013-09-13 18:07:37 +08:00
break;
case TEST_COCOSTUDIO_WITH_SKELETON:
pLayer = new (std::nothrow) TestCSWithSkeleton();
2013-09-13 18:07:37 +08:00
break;
case TEST_PERFORMANCE:
pLayer = new (std::nothrow) TestPerformance();
2013-09-13 18:07:37 +08:00
break;
2013-12-17 17:00:01 +08:00
// case TEST_PERFORMANCE_BATCHNODE:
// pLayer = new (std::nothrow) TestPerformanceBatchNode();
2013-12-17 17:00:01 +08:00
// break;
2013-09-13 18:07:37 +08:00
case TEST_CHANGE_ZORDER:
pLayer = new (std::nothrow) TestChangeZorder();
2013-09-13 18:07:37 +08:00
break;
case TEST_ANIMATION_EVENT:
pLayer = new (std::nothrow) TestAnimationEvent();
2013-09-13 18:07:37 +08:00
break;
case TEST_FRAME_EVENT:
pLayer = new (std::nothrow) TestFrameEvent();
break;
2013-09-13 18:07:37 +08:00
case TEST_PARTICLE_DISPLAY:
pLayer = new (std::nothrow) TestParticleDisplay();
2013-09-13 18:07:37 +08:00
break;
case TEST_USE_DIFFERENT_PICTURE:
pLayer = new (std::nothrow) TestUseMutiplePicture();
2013-09-13 18:07:37 +08:00
break;
case TEST_COLLIDER_DETECTOR:
pLayer = new (std::nothrow) TestColliderDetector();
2013-09-13 18:07:37 +08:00
break;
case TEST_BOUDINGBOX:
pLayer = new (std::nothrow) TestBoundingBox();
2013-09-13 18:07:37 +08:00
break;
case TEST_ANCHORPOINT:
pLayer = new (std::nothrow) TestAnchorPoint();
2013-09-13 18:07:37 +08:00
break;
case TEST_ARMATURE_NESTING:
pLayer = new (std::nothrow) TestArmatureNesting();
2013-09-13 18:07:37 +08:00
break;
2013-10-30 09:41:40 +08:00
case TEST_ARMATURE_NESTING_2:
pLayer = new (std::nothrow) TestArmatureNesting2();
2013-10-30 09:41:40 +08:00
break;
case TEST_PLAY_SEVERAL_MOVEMENT:
pLayer = new (std::nothrow) TestPlaySeveralMovement();
break;
case TEST_EASING:
pLayer = new (std::nothrow) TestEasing();
break;
case TEST_CHANGE_ANIMATION_INTERNAL:
pLayer = new (std::nothrow) TestChangeAnimationInternal();
break;
2014-06-18 20:09:12 +08:00
case TEST_DIRECT_FROM_BINARY:
pLayer = new (std::nothrow) TestLoadFromBinary();
2014-06-18 20:09:12 +08:00
break;
case TEST_ARMATURE_NODE:
pLayer = new (std::nothrow) TestArmatureNode();
break;
2013-09-13 18:07:37 +08:00
default:
break;
}
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
return pLayer;
2013-06-06 12:02:54 +08:00
}
2013-09-13 18:07:37 +08:00
Layer *NextTest()
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
++s_nActionIdx;
s_nActionIdx = s_nActionIdx % TEST_LAYER_COUNT;
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
Layer *pLayer = CreateLayer(s_nActionIdx);
pLayer->autorelease();
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
return pLayer;
2013-06-06 12:02:54 +08:00
}
2013-09-13 18:07:37 +08:00
Layer *BackTest()
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
--s_nActionIdx;
if( s_nActionIdx < 0 )
s_nActionIdx += TEST_LAYER_COUNT;
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
Layer *pLayer = CreateLayer(s_nActionIdx);
pLayer->autorelease();
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
return pLayer;
2013-06-06 12:02:54 +08:00
}
2013-09-13 18:07:37 +08:00
Layer *RestartTest()
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
Layer *pLayer = CreateLayer(s_nActionIdx);
pLayer->autorelease();
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
return pLayer;
2013-06-06 12:02:54 +08:00
}
ArmatureTestScene::ArmatureTestScene(bool bPortrait)
{
2013-09-13 18:07:37 +08:00
TestScene::init();
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
Sprite *bg = Sprite::create("armature/bg.jpg");
bg->setPosition(VisibleRect::center());
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width;
float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height;
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
bg->setScaleX(scaleX);
bg->setScaleY(scaleY);
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
addChild(bg);
2013-06-06 12:02:54 +08:00
}
void ArmatureTestScene::runThisTest()
{
2013-09-13 18:07:37 +08:00
s_nActionIdx = -1;
addChild(NextTest());
Director::getInstance()->replaceScene(this);
2013-06-06 12:02:54 +08:00
}
void ArmatureTestScene::MainMenuCallback(Ref *pSender)
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
//TestScene::MainMenuCallback(pSender);
removeAllChildren();
2013-12-27 20:54:05 +08:00
ArmatureDataManager::destroyInstance();
2013-06-06 12:02:54 +08:00
}
void ArmatureTestLayer::onEnter()
{
2013-09-13 18:07:37 +08:00
Layer::onEnter();
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
// add title and subtitle
std::string str = title();
const char *pTitle = str.c_str();
auto label = Label::createWithTTF(pTitle, "fonts/arial.ttf", 18);
label->setColor(Color3B::BLACK);
2013-09-13 18:07:37 +08:00
addChild(label, 1, 10000);
label->setPosition(VisibleRect::center().x, VisibleRect::top().y - 30);
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
std::string strSubtitle = subtitle();
if( ! strSubtitle.empty() )
{
auto l = Label::createWithTTF(strSubtitle.c_str(), "fonts/arial.ttf", 18);
l->setColor(Color3B::BLACK);
2013-09-13 18:07:37 +08:00
addChild(l, 1, 10001);
l->setPosition(VisibleRect::center().x, VisibleRect::top().y - 60);
2013-09-13 18:07:37 +08:00
}
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
// add menu
backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(ArmatureTestLayer::backCallback, this) );
restartItem = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(ArmatureTestLayer::restartCallback, this) );
nextItem = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(ArmatureTestLayer::nextCallback, this) );
2013-06-06 12:02:54 +08:00
Menu *menu = Menu::create(backItem, restartItem, nextItem, nullptr);
2013-06-06 12:02:54 +08:00
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
menu->setPosition(Vec2::ZERO);
backItem->setPosition(VisibleRect::center().x - restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2);
restartItem->setPosition(VisibleRect::center().x, VisibleRect::bottom().y + restartItem->getContentSize().height / 2);
nextItem->setPosition(VisibleRect::center().x + restartItem->getContentSize().width * 2, VisibleRect::bottom().y + restartItem->getContentSize().height / 2);
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
addChild(menu, 100);
2013-06-06 12:02:54 +08:00
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
2013-06-06 12:02:54 +08:00
}
void ArmatureTestLayer::onExit()
{
2013-09-13 18:07:37 +08:00
removeAllChildren();
backItem = restartItem = nextItem = nullptr;
2013-11-30 01:09:38 +08:00
2013-09-17 23:03:33 +08:00
Layer::onExit();
2013-06-06 12:02:54 +08:00
}
std::string ArmatureTestLayer::title() const
2013-06-06 12:02:54 +08:00
{
return "Armature Test Bed";
2013-06-06 12:02:54 +08:00
}
std::string ArmatureTestLayer::subtitle() const
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
return "";
2013-06-06 12:02:54 +08:00
}
void ArmatureTestLayer::restartCallback(Ref *pSender)
2013-06-06 12:02:54 +08:00
{
Scene *s = new (std::nothrow) ArmatureTestScene();
2013-09-13 18:07:37 +08:00
s->addChild( RestartTest() );
Director::getInstance()->replaceScene(s);
s->release();
2013-06-06 12:02:54 +08:00
}
void ArmatureTestLayer::nextCallback(Ref *pSender)
2013-06-06 12:02:54 +08:00
{
Scene *s = new (std::nothrow) ArmatureTestScene();
2013-09-13 18:07:37 +08:00
s->addChild( NextTest() );
Director::getInstance()->replaceScene(s);
s->release();
2013-06-06 12:02:54 +08:00
}
void ArmatureTestLayer::backCallback(Ref *pSender)
2013-06-06 12:02:54 +08:00
{
Scene *s = new (std::nothrow) ArmatureTestScene();
2013-09-13 18:07:37 +08:00
s->addChild( BackTest() );
Director::getInstance()->replaceScene(s);
s->release();
2013-06-06 12:02:54 +08:00
}
2013-09-13 18:07:37 +08:00
void TestAsynchronousLoading::onEnter()
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
ArmatureTestLayer::onEnter();
//CCLOG("armature version : %s", armatureVersion());
2013-09-13 18:07:37 +08:00
backItem->setEnabled(false);
restartItem->setEnabled(false);
nextItem->setEnabled(false);
char pszPercent[255];
sprintf(pszPercent, "%s %f", subtitle().c_str(), 0.0f);
auto label = (Label *)getChildByTag(10001);
2013-09-13 18:07:37 +08:00
label->setString(pszPercent);
//! create a new thread to load data
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/knight.png", "armature/knight.plist", "armature/knight.xml", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/robot.png", "armature/robot.plist", "armature/robot.xml", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/Cowboy.ExportJson", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/hero.ExportJson", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/horse.ExportJson", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/bear.ExportJson", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/HeroAnimation.ExportJson", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/testEasing.ExportJson", this, CC_SCHEDULE_SELECTOR(TestAsynchronousLoading::dataLoaded));
2013-06-06 12:02:54 +08:00
}
std::string TestAsynchronousLoading::title() const
2013-09-13 18:07:37 +08:00
{
return "Test Asynchronous Loading";
}
std::string TestAsynchronousLoading::subtitle() const
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
return "current percent : ";
}
void TestAsynchronousLoading::restartCallback(Ref* pSender)
{
2013-12-27 20:54:05 +08:00
ArmatureDataManager::destroyInstance();
ArmatureTestLayer::restartCallback(pSender);
}
2013-09-13 18:07:37 +08:00
void TestAsynchronousLoading::dataLoaded(float percent)
{
auto label = (Label *)getChildByTag(10001);
2013-09-13 18:07:37 +08:00
if (label)
{
char pszPercent[255];
sprintf(pszPercent, "%s %f", subtitle().c_str(), percent * 100);
label->setString(pszPercent);
}
if (percent >= 1 && backItem && restartItem && nextItem)
{
backItem->setEnabled(true);
restartItem->setEnabled(true);
nextItem->setEnabled(true);
}
2013-06-06 12:02:54 +08:00
}
void TestDirectLoading::onEnter()
{
ArmatureTestLayer::onEnter();
// remove sigle resource
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/bear.ExportJson");
// load resource directly
ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/bear.ExportJson");
Armature *armature = Armature::create("bear");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
armature->setPosition(VisibleRect::center().x, VisibleRect::center().y);
addChild(armature);
}
std::string TestDirectLoading::title() const
{
return "Test Direct Loading";
}
2013-09-13 18:07:37 +08:00
2013-06-06 12:02:54 +08:00
void TestCSWithSkeleton::onEnter()
{
2013-09-13 18:07:37 +08:00
ArmatureTestLayer::onEnter();
Armature *armature = nullptr;
armature = Armature::create("Cowboy");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
2013-09-13 18:07:37 +08:00
armature->setScale(0.2f);
armature->setPosition(VisibleRect::center().x, VisibleRect::center().y/*-100*/);
2013-09-13 18:07:37 +08:00
addChild(armature);
2013-06-06 12:02:54 +08:00
}
std::string TestCSWithSkeleton::title() const
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
return "Test Export From CocoStudio With Skeleton Effect";
2013-06-06 12:02:54 +08:00
}
2013-09-13 18:07:37 +08:00
void TestDragonBones20::onEnter()
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
ArmatureTestLayer::onEnter();
Armature *armature = nullptr;
armature = Armature::create("Dragon");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(1);
2013-09-13 18:07:37 +08:00
armature->getAnimation()->setSpeedScale(0.4f);
armature->setPosition(VisibleRect::center().x, VisibleRect::center().y * 0.3f);
armature->setScale(0.6f);
addChild(armature);
2013-06-06 12:02:54 +08:00
}
std::string TestDragonBones20::title() const
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
return "Test Export From DragonBones version 2.0";
2013-06-06 12:02:54 +08:00
}
2013-10-30 09:41:40 +08:00
#define ArmaturePerformanceTag 20000
2013-06-06 12:02:54 +08:00
TestPerformance::~TestPerformance()
{
}
void TestPerformance::onEnter()
{
2013-09-13 18:07:37 +08:00
ArmatureTestLayer::onEnter();
2013-06-06 12:02:54 +08:00
2013-10-30 09:41:40 +08:00
MenuItemFont::setFontSize(65);
2013-10-30 11:34:16 +08:00
MenuItemFont *decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(TestPerformance::onDecrease, this));
decrease->setColor(Color3B(0,200,20));
MenuItemFont *increase = MenuItemFont::create(" + ", CC_CALLBACK_1(TestPerformance::onIncrease, this));
increase->setColor(Color3B(0,200,20));
2013-11-30 01:09:38 +08:00
Menu *menu = Menu::create(decrease, increase, nullptr);
2013-10-30 09:41:40 +08:00
menu->alignItemsHorizontally();
menu->setPosition(VisibleRect::getVisibleRect().size.width/2, VisibleRect::getVisibleRect().size.height-100);
2013-10-30 09:41:40 +08:00
addChild(menu, 10000);
2013-09-13 18:07:37 +08:00
armatureCount = frames = times = lastTimes = 0;
generated = false;
2013-06-06 12:02:54 +08:00
2013-10-30 09:41:40 +08:00
addArmature(100);
2013-06-06 12:02:54 +08:00
}
std::string TestPerformance::title() const
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
return "Test Performance";
2013-06-06 12:02:54 +08:00
}
std::string TestPerformance::subtitle() const
2013-06-06 12:02:54 +08:00
{
return "Current Armature Count : ";
2013-06-06 12:02:54 +08:00
}
void TestPerformance::onIncrease(Ref* pSender)
2013-06-06 12:02:54 +08:00
{
2013-10-30 09:41:40 +08:00
addArmature(20);
2013-06-06 12:02:54 +08:00
}
void TestPerformance::onDecrease(Ref* pSender)
2013-06-06 12:02:54 +08:00
{
2013-10-30 09:41:40 +08:00
if (armatureCount == 0)
return;
2013-06-06 12:02:54 +08:00
2013-10-30 09:41:40 +08:00
for (int i = 0; i<20; i++)
2013-09-13 18:07:37 +08:00
{
2013-10-30 09:41:40 +08:00
removeArmatureFromParent(ArmaturePerformanceTag + armatureCount);
armatureCount --;
2013-11-30 01:09:38 +08:00
refreshTitle();
2013-10-30 09:41:40 +08:00
}
}
void TestPerformance::addArmature(int number)
{
for (int i = 0; i<number; i++)
{
armatureCount++;
Armature *armature = nullptr;
armature = new (std::nothrow) Armature();
2014-06-17 11:13:46 +08:00
armature->init("Cowboy");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
2013-09-13 18:07:37 +08:00
armature->setPosition(50 + armatureCount * 2, 150);
2014-06-17 11:45:57 +08:00
armature->setScale(0.1f);
2013-10-30 09:41:40 +08:00
addArmatureToParent(armature);
2013-09-13 18:07:37 +08:00
armature->release();
}
2013-06-06 12:02:54 +08:00
2013-11-30 01:09:38 +08:00
refreshTitle();
2013-10-30 09:41:40 +08:00
}
void TestPerformance::addArmatureToParent(cocostudio::Armature *armature)
{
addChild(armature, 0, ArmaturePerformanceTag + armatureCount);
}
void TestPerformance::removeArmatureFromParent(int tag)
{
removeChildByTag(ArmaturePerformanceTag + armatureCount);
}
2013-11-30 01:09:38 +08:00
void TestPerformance::refreshTitle()
2013-10-30 09:41:40 +08:00
{
char pszCount[255];
sprintf(pszCount, "%s %i", subtitle().c_str(), armatureCount);
auto label = (Label *)getChildByTag(10001);
2013-10-30 09:41:40 +08:00
label->setString(pszCount);
}
2013-06-06 12:02:54 +08:00
2013-10-30 09:41:40 +08:00
void TestPerformanceBatchNode::onEnter()
{
batchNode = BatchNode::create();
addChild(batchNode);
2013-06-06 12:02:54 +08:00
2013-10-30 09:41:40 +08:00
TestPerformance::onEnter();
}
std::string TestPerformanceBatchNode::title() const
2013-10-30 09:41:40 +08:00
{
return "Test Performance of using BatchNode";
}
void TestPerformanceBatchNode::addArmatureToParent(cocostudio::Armature *armature)
{
batchNode->addChild(armature, 0, ArmaturePerformanceTag + armatureCount);
}
void TestPerformanceBatchNode::removeArmatureFromParent(int tag)
{
batchNode->removeChildByTag(ArmaturePerformanceTag + armatureCount);
}
2013-06-06 12:02:54 +08:00
void TestChangeZorder::onEnter()
{
2013-09-13 18:07:37 +08:00
ArmatureTestLayer::onEnter();
2013-06-06 12:02:54 +08:00
Armature *armature = nullptr;
2013-09-13 18:07:37 +08:00
currentTag = -1;
2013-06-06 12:02:54 +08:00
armature = Armature::create("Knight_f/Knight");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
armature->setPosition(VisibleRect::center().x, VisibleRect::center().y - 100);
2013-09-13 18:07:37 +08:00
++currentTag;
armature->setScale(0.6f);
addChild(armature, currentTag, currentTag);
2013-06-06 12:02:54 +08:00
armature = Armature::create("Cowboy");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
2013-09-13 18:07:37 +08:00
armature->setScale(0.24f);
armature->setPosition(VisibleRect::center().x, VisibleRect::center().y - 100);
2013-09-13 18:07:37 +08:00
++currentTag;
addChild(armature, currentTag, currentTag);
2013-06-06 12:02:54 +08:00
armature = Armature::create("Dragon");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
armature->setPosition(VisibleRect::center().x , VisibleRect::center().y - 100);
2013-09-13 18:07:37 +08:00
++currentTag;
armature->setScale(0.6f);
addChild(armature, currentTag, currentTag);
2013-06-06 12:02:54 +08:00
schedule( CC_SCHEDULE_SELECTOR(TestChangeZorder::changeZorder), 1);
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
currentTag = 0;
2013-06-06 12:02:54 +08:00
}
std::string TestChangeZorder::title() const
2013-06-06 12:02:54 +08:00
{
return "Test Change ZOrder Of Different Armature";
2013-06-06 12:02:54 +08:00
}
void TestChangeZorder::changeZorder(float dt)
{
2013-09-13 18:07:37 +08:00
Node *node = getChildByTag(currentTag);
node->setLocalZOrder(CCRANDOM_0_1() * 3);
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
currentTag ++;
currentTag = currentTag % 3;
2013-06-06 12:02:54 +08:00
}
void TestAnimationEvent::onEnter()
{
2013-09-13 18:07:37 +08:00
ArmatureTestLayer::onEnter();
armature = Armature::create("Cowboy");
2013-09-13 18:07:37 +08:00
armature->getAnimation()->play("Fire");
armature->setScaleX(-0.24f);
armature->setScaleY(0.24f);
armature->setPosition(VisibleRect::left().x + 50, VisibleRect::left().y);
2013-09-13 18:07:37 +08:00
/*
* Set armature's movement event callback function
* To disconnect this event, just setMovementEventCallFunc(nullptr, nullptr);
2013-09-13 18:07:37 +08:00
*/
2013-12-19 10:42:06 +08:00
armature->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_0(TestAnimationEvent::animationEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
2013-09-13 18:07:37 +08:00
addChild(armature);
2013-06-06 12:02:54 +08:00
}
std::string TestAnimationEvent::title() const
2013-06-06 12:02:54 +08:00
{
return "Test Armature Animation Event";
2013-09-13 18:07:37 +08:00
}
void TestAnimationEvent::animationEvent(Armature *armature, MovementEventType movementType, const std::string& movementID)
2013-09-13 18:07:37 +08:00
{
if (movementType == LOOP_COMPLETE)
{
2013-12-24 14:21:25 +08:00
if (movementID == "Fire")
2013-09-13 18:07:37 +08:00
{
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
ActionInterval *actionToRight = MoveTo::create(2, Vec2(VisibleRect::right().x - 50, VisibleRect::right().y));
2013-09-13 18:07:37 +08:00
armature->stopAllActions();
armature->runAction(Sequence::create(actionToRight, CallFunc::create( CC_CALLBACK_0(TestAnimationEvent::callback1, this)), nullptr));
2013-09-13 18:07:37 +08:00
armature->getAnimation()->play("Walk");
}
2013-12-24 14:21:25 +08:00
else if (movementID == "FireMax")
2013-09-13 18:07:37 +08:00
{
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
ActionInterval *actionToLeft = MoveTo::create(2, Vec2(VisibleRect::left().x + 50, VisibleRect::left().y));
2013-09-13 18:07:37 +08:00
armature->stopAllActions();
armature->runAction(Sequence::create(actionToLeft, CallFunc::create( CC_CALLBACK_0(TestAnimationEvent::callback2, this)), nullptr));
2013-09-13 18:07:37 +08:00
armature->getAnimation()->play("Walk");
}
}
2013-06-06 12:02:54 +08:00
}
void TestAnimationEvent::callback1()
{
2013-09-13 18:07:37 +08:00
armature->runAction(ScaleTo::create(0.3f, 0.24f, 0.24f));
armature->getAnimation()->play("FireMax", 10);
2013-06-06 12:02:54 +08:00
}
void TestAnimationEvent::callback2()
{
2013-09-13 18:07:37 +08:00
armature->runAction(ScaleTo::create(0.3f, -0.24f, 0.24f));
armature->getAnimation()->play("Fire", 10);
2013-06-06 12:02:54 +08:00
}
#define FRAME_EVENT_ACTION_TAG 10000
void TestFrameEvent::onEnter()
{
ArmatureTestLayer::onEnter();
_gridNode = NodeGrid::create();
Armature *armature = Armature::create("HeroAnimation");
armature->getAnimation()->play("attack");
armature->getAnimation()->setSpeedScale(0.5);
armature->setPosition(VisibleRect::center().x - 50, VisibleRect::center().y -100);
/*
* Set armature's frame event callback function
2013-12-18 22:07:33 +08:00
* To disconnect this event, just setFrameEventCallFunc(nullptr);
*/
2013-12-19 10:42:06 +08:00
armature->getAnimation()->setFrameEventCallFunc(CC_CALLBACK_0(TestFrameEvent::onFrameEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
2013-12-11 13:40:04 +08:00
_gridNode->addChild(armature);
addChild(_gridNode);
schedule( CC_SCHEDULE_SELECTOR(TestFrameEvent::checkAction) );
}
std::string TestFrameEvent::title() const
{
return "Test Frame Event";
}
void TestFrameEvent::onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex)
{
CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt.c_str(), currentFrameIndex);
2013-12-11 13:40:04 +08:00
if (!_gridNode->getActionByTag(FRAME_EVENT_ACTION_TAG) || _gridNode->getActionByTag(FRAME_EVENT_ACTION_TAG)->isDone())
{
2013-12-11 13:40:04 +08:00
_gridNode->stopAllActions();
2013-11-30 01:09:38 +08:00
ActionInterval *action = ShatteredTiles3D::create(0.2f, Size(16,12), 5, false);
action->setTag(FRAME_EVENT_ACTION_TAG);
2013-12-11 13:40:04 +08:00
_gridNode->runAction(action);
}
}
void TestFrameEvent::checkAction(float dt)
{
if ( _gridNode->getNumberOfRunningActions() == 0 && _gridNode->getGrid() != nullptr)
_gridNode->setGrid(nullptr);
}
2013-06-06 12:02:54 +08:00
void TestParticleDisplay::onEnter()
{
2013-09-13 18:07:37 +08:00
ArmatureTestLayer::onEnter();
2013-11-30 01:09:38 +08:00
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesEnded = CC_CALLBACK_2(TestParticleDisplay::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
2013-09-13 18:07:37 +08:00
animationID = 0;
armature = Armature::create("robot");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
2013-09-13 18:07:37 +08:00
armature->setPosition(VisibleRect::center());
armature->setScale(0.48f);
armature->getAnimation()->setSpeedScale(0.5f);
addChild(armature);
ParticleSystem *p1 = CCParticleSystemQuad::create("Particles/SmallSun.plist");
ParticleSystem *p2 = CCParticleSystemQuad::create("Particles/SmallSun.plist");
cocostudio::Bone *bone = cocostudio::Bone::create("p1");
2013-09-13 18:07:37 +08:00
bone->addDisplay(p1, 0);
2014-01-02 11:07:31 +08:00
bone->changeDisplayWithIndex(0, true);
2013-09-13 18:07:37 +08:00
bone->setIgnoreMovementBoneData(true);
bone->setLocalZOrder(100);
2013-09-13 18:07:37 +08:00
bone->setScale(1.2f);
armature->addBone(bone, "bady-a3");
bone = cocostudio::Bone::create("p2");
2013-09-13 18:07:37 +08:00
bone->addDisplay(p2, 0);
2014-01-02 11:07:31 +08:00
bone->changeDisplayWithIndex(0, true);
2013-09-13 18:07:37 +08:00
bone->setIgnoreMovementBoneData(true);
bone->setLocalZOrder(100);
2013-09-13 18:07:37 +08:00
bone->setScale(1.2f);
armature->addBone(bone, "bady-a30");
}
2013-09-16 19:27:34 +08:00
2013-09-13 18:07:37 +08:00
void TestParticleDisplay::onExit()
{
ArmatureTestLayer::onExit();
2013-06-06 12:02:54 +08:00
}
2013-09-16 19:27:34 +08:00
std::string TestParticleDisplay::title() const
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
return "Test Particle Display";
2013-06-06 12:02:54 +08:00
}
2013-09-16 19:27:34 +08:00
std::string TestParticleDisplay::subtitle() const
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
return "Touch to change animation";
2013-06-06 12:02:54 +08:00
}
2013-09-16 19:27:34 +08:00
void TestParticleDisplay::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
++animationID;
animationID = animationID % armature->getAnimation()->getMovementCount();
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(animationID);
2013-06-06 12:02:54 +08:00
}
void TestUseMutiplePicture::onEnter()
{
2013-09-13 18:07:37 +08:00
ArmatureTestLayer::onEnter();
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesEnded = CC_CALLBACK_2(TestUseMutiplePicture::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
2013-11-30 01:09:38 +08:00
2013-09-13 18:07:37 +08:00
displayIndex = 0;
armature = Armature::create("Knight_f/Knight");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
armature->setPosition(VisibleRect::center().x, VisibleRect::left().y);
2013-09-13 18:07:37 +08:00
armature->setScale(1.2f);
addChild(armature);
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +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-09-13 18:07:37 +08:00
for (int i = 0; i < 7; i++)
{
Skin *skin = Skin::createWithSpriteFrameName(weapon[i].c_str());
2013-09-13 18:07:37 +08:00
armature->getBone("weapon")->addDisplay(skin, i);
}
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
// CCSpriteDisplayData displayData;
// for (int i = 0; i < 7; i++)
// {
// displayData.setParam(weapon[i].c_str());
// armature->getBone("weapon")->addDisplay(&displayData, i);
// }
2013-06-06 12:02:54 +08:00
auto l = Label::createWithTTF("This is a weapon!", "fonts/arial.ttf", 18);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
l->setAnchorPoint(Vec2(0.2f, 0.5f));
2013-09-13 18:07:37 +08:00
armature->getBone("weapon")->addDisplay(l, 7);
}
2013-09-16 19:27:34 +08:00
2013-09-13 18:07:37 +08:00
void TestUseMutiplePicture::onExit()
{
ArmatureTestLayer::onExit();
2013-06-06 12:02:54 +08:00
}
2013-09-16 19:27:34 +08:00
std::string TestUseMutiplePicture::title() const
2013-06-06 12:02:54 +08:00
{
return "Test One Armature Use Different Picture";
2013-06-06 12:02:54 +08:00
}
2013-09-16 19:27:34 +08:00
std::string TestUseMutiplePicture::subtitle() const
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
return "weapon and armature are in different picture";
2013-06-06 12:02:54 +08:00
}
2013-09-16 19:27:34 +08:00
void TestUseMutiplePicture::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
++displayIndex;
displayIndex = (displayIndex) % 8;
2014-01-02 11:07:31 +08:00
armature->getBone("weapon")->changeDisplayWithIndex(displayIndex, true);
2013-09-13 18:07:37 +08:00
}
TestColliderDetector::~TestColliderDetector()
{
}
void TestColliderDetector::onEnter()
{
ArmatureTestLayer::onEnter();
scheduleUpdate();
armature = Armature::create("Cowboy");
2013-09-13 18:07:37 +08:00
armature->getAnimation()->play("FireWithoutBullet");
armature->getAnimation()->setSpeedScale(0.2f);
armature->setScaleX(-0.2f);
armature->setScaleY(0.2f);
armature->setPosition(VisibleRect::left().x + 70, VisibleRect::left().y);
2013-09-13 18:07:37 +08:00
/*
* Set armature's frame event callback function
2013-12-18 22:07:33 +08:00
* To disconnect this event, just setFrameEventCallFunc(nullptr);
2013-09-13 18:07:37 +08:00
*/
2013-12-19 10:42:06 +08:00
armature->getAnimation()->setFrameEventCallFunc(CC_CALLBACK_0(TestColliderDetector::onFrameEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
2013-09-13 18:07:37 +08:00
addChild(armature);
armature2 = Armature::create("Cowboy");
2013-09-13 18:07:37 +08:00
armature2->getAnimation()->play("Walk");
armature2->setScaleX(-0.2f);
armature2->setScaleY(0.2f);
armature2->setPosition(VisibleRect::right().x - 60, VisibleRect::left().y);
2013-09-13 18:07:37 +08:00
addChild(armature2);
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
2013-12-06 14:25:08 +08:00
bullet = cocos2d::extension::PhysicsSprite::createWithSpriteFrameName("25.png");
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
bullet = Sprite::createWithSpriteFrameName("25.png");
drawNode = DrawNode::create();
addChild(drawNode, -1);
#endif
2013-09-13 18:07:37 +08:00
addChild(bullet);
initWorld();
}
std::string TestColliderDetector::title() const
2013-09-13 18:07:37 +08:00
{
return "Test Collider Detector";
}
void TestColliderDetector::onFrameEvent(cocostudio::Bone *bone, const std::string& evt, int originFrameIndex, int currentFrameIndex)
2013-09-13 18:07:37 +08:00
{
CCLOG("(%s) emit a frame event (%s) at frame index (%d).", bone->getName().c_str(), evt.c_str(), currentFrameIndex);
2013-09-13 18:07:37 +08:00
/*
* originFrameIndex is the frame index editted in Action Editor
* currentFrameIndex is the current index animation played to
* frame event may be delay emit, so originFrameIndex may be different from currentFrameIndex.
*/
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 p = armature->getBone("Layer126")->getDisplayRenderNode()->convertToWorldSpaceAR(Vec2(0, 0));
bullet->setPosition(p.x + 60, p.y);
2013-09-13 18:07:37 +08:00
bullet->stopAllActions();
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
bullet->runAction(CCMoveBy::create(1.5f, Vec2(350, 0)));
2013-06-06 12:02:54 +08:00
}
2013-09-13 18:07:37 +08:00
#if ENABLE_PHYSICS_BOX2D_DETECT
class Contact
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
public:
b2Fixture *fixtureA;
b2Fixture *fixtureB;
};
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
class ContactListener : public b2ContactListener
{
//! Callbacks for derived classes.
virtual void BeginContact(b2Contact *contact)
{
if (contact)
{
Contact c;
c.fixtureA = contact->GetFixtureA();
c.fixtureB = contact->GetFixtureB();
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
contact_list.push_back(c);
}
B2_NOT_USED(contact);
}
virtual void EndContact(b2Contact *contact)
{
contact_list.clear();
B2_NOT_USED(contact);
}
virtual void PreSolve(b2Contact *contact, const b2Manifold *oldManifold)
{
B2_NOT_USED(contact);
B2_NOT_USED(oldManifold);
}
virtual void PostSolve(const b2Contact *contact, const b2ContactImpulse *impulse)
{
B2_NOT_USED(contact);
B2_NOT_USED(impulse);
}
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
public:
std::list<Contact> contact_list;
};
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
void TestColliderDetector::onExit()
{
CC_SAFE_DELETE(world);
CC_SAFE_DELETE(listener);
CC_SAFE_DELETE(debugDraw);
ArmatureTestLayer::onExit();
2013-06-06 12:02:54 +08:00
}
void TestColliderDetector::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
2013-06-06 12:02:54 +08:00
{
2013-12-09 13:56:07 +08:00
GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION );
Director* director = Director::getInstance();
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
2013-09-13 18:07:37 +08:00
world->DrawDebugData();
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
2013-06-06 12:02:54 +08:00
}
2013-09-13 18:07:37 +08:00
void TestColliderDetector::update(float delta)
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
armature2->setVisible(true);
world->Step(delta, 0, 0);
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
for (std::list<Contact>::iterator it = listener->contact_list.begin(); it != listener->contact_list.end(); ++it)
{
Contact &contact = *it;
2013-06-06 12:02:54 +08:00
2013-12-18 22:36:10 +08:00
Bone *bb = static_cast<Bone *>(contact.fixtureB->GetUserData);
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
bb->getArmature()->setVisible(false);
}
2013-06-06 12:02:54 +08:00
}
2013-09-13 18:07:37 +08:00
void TestColliderDetector::initWorld()
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
b2Vec2 noGravity(0, 0);
world = new b2World(noGravity);
world->SetAllowSleeping(true);
listener = new (std::nothrow) ContactListener();
2013-09-13 18:07:37 +08:00
world->SetContactListener(listener);
debugDraw = new (std::nothrow) GLESDebugDraw( PT_RATIO );
2013-09-13 18:07:37 +08:00
world->SetDebugDraw(debugDraw);
uint32 flags = 0;
flags += b2Draw::e_shapeBit;
// flags += b2Draw::e_jointBit;
// flags += b2Draw::e_aabbBit;
// flags += b2Draw::e_pairBit;
// flags += b2Draw::e_centerOfMassBit;
debugDraw->SetFlags(flags);
// Define the dynamic body.
//Set up a 1m squared box in the physics world
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
b2Body *body = world->CreateBody(&bodyDef);
// Define another box shape for our dynamic body.
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box
// Define the dynamic body fixture.
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.isSensor = true;
body->CreateFixture(&fixtureDef);
bullet->setB2Body(body);
bullet->setPTMRatio(PT_RATIO);
bullet->setPosition(-100, -100);
2013-09-13 18:07:37 +08:00
body = world->CreateBody(&bodyDef);
armature2->setBody(body);
}
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
enum ColliderType
{
eBulletTag,
eEnemyTag
};
int TestColliderDetector::beginHit(cpArbiter *arb, cpSpace *space, void *unused)
{
CP_ARBITER_GET_SHAPES(arb, a, b);
Bone *bone = (Bone *)a->data;
2013-09-13 18:07:37 +08:00
bone->getArmature()->setVisible(false);
return 0;
2013-06-06 12:02:54 +08:00
}
2013-09-13 18:07:37 +08:00
void TestColliderDetector::endHit(cpArbiter *arb, cpSpace *space, void *unused)
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
CP_ARBITER_GET_SHAPES(arb, a, b);
Bone *bone = (Bone *)a->data;
2013-09-13 18:07:37 +08:00
bone->getArmature()->setVisible(true);
2013-06-06 12:02:54 +08:00
}
2013-09-13 18:07:37 +08:00
void TestColliderDetector::destroyCPBody(cpBody *body)
{
cpShape *shape = body->shapeList_private;
while(shape)
{
cpShape *temp = shape->next_private;
cpSpaceRemoveShape(space, shape);
cpShapeFree(shape);
shape = temp;
}
cpSpaceRemoveBody(space, body);
cpBodyFree(body);
}
void TestColliderDetector::onExit()
{
destroyCPBody(armature2->getBody());
destroyCPBody(bullet->getCPBody());
cpSpaceFree(space);
ArmatureTestLayer::onExit();
}
void TestColliderDetector::update(float delta)
{
cpSpaceStep(space, delta);
}
void TestColliderDetector::initWorld()
{
space = cpSpaceNew();
space->gravity = cpv(0, 0);
2013-09-27 07:23:13 +08:00
#if CC_ENABLE_CHIPMUNK_INTEGRATION
2013-09-13 18:07:37 +08:00
// Physics debug layer
cocos2d::extension::PhysicsDebugNode *debugLayer = cocos2d::extension::PhysicsDebugNode::create(space);
this->addChild(debugLayer, INT_MAX);
2013-09-27 07:23:13 +08:00
#endif
2013-09-13 18:07:37 +08:00
Size size = bullet->getContentSize();
int num = 4;
cpVect verts[] =
{
cpv(-size.width / 2, -size.height / 2),
cpv(-size.width / 2, size.height / 2),
cpv(size.width / 2, size.height / 2),
cpv(size.width / 2, -size.height / 2),
};
cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero));
cpSpaceAddBody(space, body);
cpShape *shape = cpPolyShapeNew(body, num, verts, cpvzero);
shape->collision_type = eBulletTag;
cpSpaceAddShape(space, shape);
bullet->setCPBody(body);
body = cpBodyNew(1.0f, INFINITY);
2013-09-13 18:07:37 +08:00
cpSpaceAddBody(space, body);
armature2->setBody(body);
2013-11-05 13:42:27 +08:00
ColliderFilter filter = ColliderFilter(eEnemyTag);
armature2->setColliderFilter(&filter);
2013-09-13 18:07:37 +08:00
cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, nullptr, nullptr, endHit, nullptr);
2013-09-13 18:07:37 +08:00
}
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
void TestColliderDetector::update(float delta)
{
armature2->setVisible(true);
Rect rect = bullet->getBoundingBox();
// This code is just telling how to get the vertex.
// For a more accurate collider detection, you need to implemente yourself.
const Map<std::string, cocostudio::Bone*>& map = armature2->getBoneDic();
2014-01-07 20:54:34 +08:00
for(const auto& element : map)
{
cocostudio::Bone *bone = element.second;
ColliderDetector *detector = bone->getColliderDetector();
if (!detector)
continue;
const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();
2014-01-07 20:54:34 +08:00
for (const auto& object : bodyList)
{
ColliderBody *body = static_cast<ColliderBody*>(object);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
const std::vector<Vec2> &vertexList = body->getCalculatedVertexList();
2014-01-07 20:54:34 +08:00
float minx = 0, miny = 0, maxx = 0, maxy = 0;
2014-03-20 16:24:55 +08:00
size_t length = vertexList.size();
2014-03-24 10:12:40 +08:00
for (size_t i = 0; i<length; i++)
{
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 vertex = vertexList.at(i);
if (i == 0)
{
2013-12-13 19:40:38 +08:00
minx = maxx = vertex.x;
miny = maxy = vertex.y;
}
else
{
2013-12-13 19:40:38 +08:00
minx = vertex.x < minx ? vertex.x : minx;
miny = vertex.y < miny ? vertex.y : miny;
maxx = vertex.x > maxx ? vertex.x : maxx;
maxy = vertex.y > maxy ? vertex.y : maxy;
}
}
Rect temp = Rect(minx, miny, maxx - minx, maxy - miny);
if (temp.intersectsRect(rect))
{
armature2->setVisible(false);
}
}
}
}
void TestColliderDetector::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
for(auto& element : armature2->getBoneDic())
{
Bone *bone = element.second;
ColliderDetector *detector = bone->getColliderDetector();
if (!detector)
continue;
const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();
for (auto& object : bodyList)
{
ColliderBody *body = static_cast<ColliderBody*>(object);
const std::vector<Vec2> &vertexList = body->getCalculatedVertexList();
unsigned long length = vertexList.size();
Vec2 *points = new Vec2[length];
for (unsigned long i = 0; i<length; i++)
{
Vec2 p = vertexList.at(i);
points[i].x = p.x;
points[i].y = p.y;
}
drawNode->clear();
drawNode->drawPoly(points, (unsigned int)length, true, Color4F(1.0, 1.0, 1.0, 1.0));
delete []points;
}
}
}
2013-09-13 18:07:37 +08:00
#endif
2013-06-06 12:02:54 +08:00
void TestBoundingBox::onEnter()
{
2013-09-13 18:07:37 +08:00
ArmatureTestLayer::onEnter();
armature = Armature::create("Cowboy");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
2013-09-13 18:07:37 +08:00
armature->setPosition(VisibleRect::center());
armature->setScale(0.2f);
addChild(armature);
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
Sprite *sprite = Sprite::create("Images/background3.png");
armature->addChild(sprite);
_drawNode = DrawNode::create();
this->addChild(_drawNode);
2013-06-06 12:02:54 +08:00
}
std::string TestBoundingBox::title() const
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
return "Test BoundingBox";
2013-06-06 12:02:54 +08:00
}
void TestBoundingBox::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
2013-06-06 12:02:54 +08:00
{
2013-10-30 09:41:40 +08:00
rect = armature->getBoundingBox();
_drawNode->clear();
_drawNode->drawRect(rect.origin, Vec2(rect.getMaxX(), rect.getMaxY()), Color4F(1.0, 0.5, 0.5, 1.0));
2013-06-06 12:02:54 +08:00
}
void TestAnchorPoint::onEnter()
{
2013-09-13 18:07:37 +08:00
ArmatureTestLayer::onEnter();
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
for (int i = 0; i < 5; i++)
{
Armature *armature = Armature::create("Cowboy");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
2013-09-13 18:07:37 +08:00
armature->setPosition(VisibleRect::center());
armature->setScale(0.2f);
addChild(armature, 0, i);
}
2013-06-06 12:02:54 +08:00
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
getChildByTag(0)->setAnchorPoint(Vec2(0, 0));
getChildByTag(1)->setAnchorPoint(Vec2(0, 1));
getChildByTag(2)->setAnchorPoint(Vec2(1, 0));
getChildByTag(3)->setAnchorPoint(Vec2(1, 1));
getChildByTag(4)->setAnchorPoint(Vec2(0.5, 0.5));
2013-06-06 12:02:54 +08:00
}
std::string TestAnchorPoint::title() const
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
return "Test Set AnchorPoint";
2013-06-06 12:02:54 +08:00
}
void TestArmatureNesting::onEnter()
{
2013-09-13 18:07:37 +08:00
ArmatureTestLayer::onEnter();
2013-11-30 01:09:38 +08:00
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesEnded = CC_CALLBACK_2(TestArmatureNesting::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
2013-06-06 12:02:54 +08:00
armature = Armature::create("cyborg");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(1);
2013-09-13 18:07:37 +08:00
armature->setPosition(VisibleRect::center());
armature->setScale(1.2f);
armature->getAnimation()->setSpeedScale(0.4f);
addChild(armature);
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
weaponIndex = 0;
}
2013-09-16 19:27:34 +08:00
2013-09-13 18:07:37 +08:00
void TestArmatureNesting::onExit()
{
ArmatureTestLayer::onExit();
2013-06-06 12:02:54 +08:00
}
2013-09-16 19:27:34 +08:00
std::string TestArmatureNesting::title() const
2013-06-06 12:02:54 +08:00
{
return "Test Armature Nesting";
2013-06-06 12:02:54 +08:00
}
2013-09-16 19:27:34 +08:00
void TestArmatureNesting::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
2013-06-06 12:02:54 +08:00
{
2013-09-13 18:07:37 +08:00
++weaponIndex;
weaponIndex = weaponIndex % 4;
if(armature != nullptr)
2013-09-13 18:07:37 +08:00
{
2013-12-25 16:46:31 +08:00
armature->getBone("armInside")->getChildArmature()->getAnimation()->playWithIndex(weaponIndex);
armature->getBone("armOutside")->getChildArmature()->getAnimation()->playWithIndex(weaponIndex);
2013-09-13 18:07:37 +08:00
}
2013-06-06 12:02:54 +08:00
}
2013-10-30 09:41:40 +08:00
Hero *Hero::create(const char *name)
{
Hero *hero = new (std::nothrow) Hero();
2013-10-30 09:41:40 +08:00
if (hero && hero->init(name))
{
hero->autorelease();
return hero;
}
CC_SAFE_DELETE(hero);
return nullptr;
2013-10-30 09:41:40 +08:00
}
Hero::Hero()
: m_pMount(nullptr)
, m_pLayer(nullptr)
2013-10-30 09:41:40 +08:00
{
}
void Hero::changeMount(Armature *armature)
{
if (armature == nullptr)
2013-10-30 09:41:40 +08:00
{
retain();
2013-12-25 16:46:31 +08:00
playWithIndex(0);
2013-10-30 09:41:40 +08:00
//Remove hero from display list
m_pMount->getBone("hero")->removeDisplay(0);
m_pMount->stopAllActions();
//Set position to current position
setPosition(m_pMount->getPosition());
//Add to layer
m_pLayer->addChild(this);
release();
setMount(armature);
}
else
{
setMount(armature);
retain();
//Remove from layer
removeFromParentAndCleanup(false);
//Get the hero bone
cocostudio::Bone *bone = armature->getBone("hero");
2013-10-30 09:41:40 +08:00
//Add hero as a display to this bone
bone->addDisplay(this, 0);
//Change this bone's display
2014-01-02 11:07:31 +08:00
bone->changeDisplayWithIndex(0, true);
2013-10-30 09:41:40 +08:00
bone->setIgnoreMovementBoneData(true);
setPosition(0,0);
2013-10-30 09:41:40 +08:00
//Change animation
2013-12-25 16:46:31 +08:00
playWithIndex(1);
2013-10-30 09:41:40 +08:00
setScale(1);
release();
}
}
2013-12-25 16:46:31 +08:00
void Hero::playWithIndex(int index)
2013-10-30 09:41:40 +08:00
{
2013-12-25 16:46:31 +08:00
_animation->playWithIndex(index);
2013-10-30 09:41:40 +08:00
if (m_pMount)
{
2013-12-25 16:46:31 +08:00
m_pMount->getAnimation()->playWithIndex(index);
2013-10-30 09:41:40 +08:00
}
}
void TestArmatureNesting2::onEnter()
{
ArmatureTestLayer::onEnter();
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesEnded = CC_CALLBACK_2(TestArmatureNesting2::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
touchedMenu = false;
auto label = Label::createWithTTF("Change Mount", "fonts/arial.ttf", 20);
2014-01-07 20:54:34 +08:00
MenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, CC_CALLBACK_1(TestArmatureNesting2::changeMountCallback, this));
2013-10-30 09:41:40 +08:00
Menu* pMenu =Menu::create(pMenuItem, nullptr);
2013-10-30 09:41:40 +08:00
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
pMenu->setPosition( Vec2() );
pMenuItem->setPosition(VisibleRect::right().x - 67, VisibleRect::bottom().y + 50);
2013-10-30 09:41:40 +08:00
addChild(pMenu, 2);
//Create a hero
hero = Hero::create("hero");
hero->setLayer(this);
2013-12-25 16:46:31 +08:00
hero->playWithIndex(0);
hero->setPosition(VisibleRect::left().x + 20, VisibleRect::left().y);
2013-10-30 09:41:40 +08:00
addChild(hero);
//Create 3 mount
horse = createMount("horse", VisibleRect::center());
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
horse2 = createMount("horse", Vec2(120, 200));
2013-10-30 09:41:40 +08:00
horse2->setOpacity(200);
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
bear = createMount("bear", Vec2(300,70));
2013-10-30 09:41:40 +08:00
}
void TestArmatureNesting2::onExit()
{
ArmatureTestLayer::onExit();
}
std::string TestArmatureNesting2::title() const
2013-10-30 09:41:40 +08:00
{
return "Test CCArmature Nesting 2";
}
std::string TestArmatureNesting2::subtitle() const
2013-10-30 09:41:40 +08:00
{
return "Move to a mount and press the ChangeMount Button.";
}
void TestArmatureNesting2::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 point = touches[0]->getLocation();
2013-10-30 09:41:40 +08:00
2013-11-30 01:09:38 +08:00
Armature *armature = hero->getMount() == nullptr ? hero : hero->getMount();
2013-10-30 09:41:40 +08:00
//Set armature direction
if (point.x < armature->getPositionX())
{
armature->setScaleX(-1);
}
else
{
armature->setScaleX(1);
}
ActionInterval *move = CCMoveTo::create(2, point);
armature->stopAllActions();
armature->runAction(Sequence::create(move, nullptr));
2013-10-30 09:41:40 +08:00
}
void TestArmatureNesting2::changeMountCallback(Ref* pSender)
2013-10-30 09:41:40 +08:00
{
hero->stopAllActions();
if (hero->getMount())
{
hero->changeMount(nullptr);
2013-10-30 09:41:40 +08:00
}
else
{
2013-10-30 11:34:16 +08:00
if (hero->getPosition().getDistance(horse->getPosition()) < 20)
2013-10-30 09:41:40 +08:00
{
hero->changeMount(horse);
}
2013-10-30 11:34:16 +08:00
else if (hero->getPosition().getDistance(horse2->getPosition()) < 20)
2013-10-30 09:41:40 +08:00
{
hero->changeMount(horse2);
}
2013-10-30 11:34:16 +08:00
else if (hero->getPosition().getDistance(bear->getPosition()) < 30)
2013-10-30 09:41:40 +08:00
{
hero->changeMount(bear);
}
}
}
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Armature * TestArmatureNesting2::createMount(const char *name, Vec2 position)
2013-10-30 09:41:40 +08:00
{
Armature *armature = Armature::create(name);
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
2013-10-30 09:41:40 +08:00
armature->setPosition(position);
addChild(armature);
return armature;
}
void TestPlaySeveralMovement::onEnter()
{
ArmatureTestLayer::onEnter();
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
2013-12-18 23:29:54 +08:00
std::string name[] = {"Walk", "FireMax", "Fire"};
std::vector<std::string> names(name, name+3);
// int index[] = {0, 1, 2};
// std::vector<int> indexes(index, index+3);
Armature *armature = nullptr;
armature = Armature::create("Cowboy");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithNames(names);
// armature->getAnimation()->playWithIndexes(indexes);
armature->setScale(0.2f);
armature->setPosition(VisibleRect::center().x, VisibleRect::center().y/*-100*/);
addChild(armature);
}
2013-12-19 10:42:06 +08:00
std::string TestPlaySeveralMovement::title() const
{
return "Test play several movement";
}
2013-12-19 10:42:06 +08:00
std::string TestPlaySeveralMovement::subtitle()const
{
return "Movement is played one by one";
}
void TestEasing::onEnter()
{
ArmatureTestLayer::onEnter();
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
animationID = 0;
armature = Armature::create("testEasing");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
armature->setScale(0.8f);
armature->setPosition(VisibleRect::center().x, VisibleRect::center().y);
addChild(armature);
updateSubTitle();
}
2013-12-19 10:42:06 +08:00
std::string TestEasing::title() const
{
return "Test easing effect";
}
2013-12-19 10:42:06 +08:00
std::string TestEasing::subtitle() const
{
return "Current easing : ";
}
void TestEasing::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
animationID++;
animationID = animationID % armature->getAnimation()->getMovementCount();
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(animationID);
updateSubTitle();
}
void TestEasing::updateSubTitle()
{
std::string str = subtitle() + armature->getAnimation()->getCurrentMovementID();
auto label = (Label *)getChildByTag(10001);
label->setString(str.c_str());
}
void TestChangeAnimationInternal::onEnter()
{
ArmatureTestLayer::onEnter();
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesEnded = CC_CALLBACK_2(TestPlaySeveralMovement::onTouchesEnded, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
Armature *armature = nullptr;
armature = Armature::create("Cowboy");
2013-12-25 16:46:31 +08:00
armature->getAnimation()->playWithIndex(0);
armature->setScale(0.2f);
armature->setPosition(VisibleRect::center().x, VisibleRect::center().y);
addChild(armature);
}
void TestChangeAnimationInternal::onExit()
{
Director::getInstance()->setAnimationInterval(1/60.0f);
ArmatureTestLayer::onExit();
}
std::string TestChangeAnimationInternal::title() const
{
return "Test change animation internal";
}
std::string TestChangeAnimationInternal::subtitle() const
{
return "Touch to change animation internal";
}
void TestChangeAnimationInternal::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
if (Director::getInstance()->getAnimationInterval() == 1/30.0f)
{
Director::getInstance()->setAnimationInterval(1/60.0f);
}
else
{
Director::getInstance()->setAnimationInterval(1/30.0f);
}
}
2014-06-18 18:11:21 +08:00
//TestDirectFromBinay
const char* TestLoadFromBinary::m_binaryFilesNames[BINARYFILECOUNT] ={"armature/bear.csb","armature/horse.csb",
"armature/Cowboy.csb","armature/hero.csb",
"armature/HeroAnimation.csb","armature/testEasing.csb"};
const char* TestLoadFromBinary::m_armatureNames[BINARYFILECOUNT] ={"bear","horse",
"Cowboy","hero",
"HeroAnimation","testEasing"};
void TestLoadFromBinary::onEnter()
{
ArmatureTestLayer::onEnter();
2014-06-18 20:09:12 +08:00
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesEnded = CC_CALLBACK_2(TestLoadFromBinary::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
2014-06-18 18:11:21 +08:00
m_armatureIndex = -1; // none
// remove json created
// remove sync resource
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/bear.ExportJson");
ArmatureDataManager::getInstance()->removeArmatureFileInfo(m_binaryFilesNames[0]);
// load from binary
ArmatureDataManager::getInstance()->addArmatureFileInfo(m_binaryFilesNames[0]);
m_armature = Armature::create(m_armatureNames[0]);
m_armature->getAnimation()->playWithIndex(0);
m_armature->setScale(1.0f);
m_armature->setPosition(VisibleRect::center().x, VisibleRect::center().y);
2014-06-18 18:11:21 +08:00
addChild(m_armature);
}
std::string TestLoadFromBinary::title() const
{
return "Test load from binary file";
}
std::string TestLoadFromBinary::subtitle() const
{
2014-06-18 20:09:12 +08:00
return "direct load.Touch to change to Asynchronous load.";
2014-06-18 18:11:21 +08:00
}
void TestLoadFromBinary::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
{
if(-1 == m_armatureIndex )
{
2014-07-17 16:01:03 +08:00
m_armatureIndex = -2; // is loading
2014-07-17 16:16:49 +08:00
// remove json created and need remove their names: exprtjsone & csbs
2014-07-17 16:13:12 +08:00
ArmatureDataManager::getInstance()->removeArmatureFileInfo(m_binaryFilesNames[0]);
2014-06-18 18:11:21 +08:00
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/Cowboy.ExportJson");
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/hero.ExportJson");
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/horse.ExportJson");
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/HeroAnimation.ExportJson");
ArmatureDataManager::getInstance()->removeArmatureFileInfo("armature/testEasing.ExportJson");
2014-07-17 16:01:03 +08:00
for( int i = 0; i < BINARYFILECOUNT; i++)
{
ArmatureDataManager::getInstance()->removeArmatureFileInfo(m_binaryFilesNames[i]);
}
for( int i = 0; i < BINARYFILECOUNT; i++)
2014-06-18 18:11:21 +08:00
{
ArmatureDataManager::getInstance()->addArmatureFileInfoAsync(m_binaryFilesNames[i], this, CC_SCHEDULE_SELECTOR(TestLoadFromBinary::dataLoaded));
2014-06-18 18:11:21 +08:00
}
}
else if(m_armatureIndex>=0 && m_armature != nullptr)
2014-06-18 18:11:21 +08:00
{
2014-07-17 16:01:03 +08:00
m_armature->removeFromParent();
2014-06-18 18:11:21 +08:00
m_armatureIndex = m_armatureIndex==BINARYFILECOUNT-1 ? 0 : m_armatureIndex+1;
m_armature = Armature::create(m_armatureNames[m_armatureIndex]);
m_armature->setPosition(VisibleRect::center().x, VisibleRect::center().y);
2014-06-18 18:11:21 +08:00
if(m_armatureIndex == 2 ) // cowboy is 0.2
m_armature->setScale(0.2f);
m_armature->getAnimation()->playWithIndex(0);
addChild(m_armature);
}
}
void TestLoadFromBinary::dataLoaded( float percent )
{
2014-06-18 20:13:06 +08:00
Label *label = (Label *)getChildByTag(10001);
2014-06-18 18:11:21 +08:00
if (label)
{
char pszPercent[255];
2014-06-18 20:13:06 +08:00
sprintf(pszPercent, "%s %f", "Asynchronous loading: ", percent * 100);
2014-06-18 18:11:21 +08:00
label->setString(pszPercent);
}
if (percent >= 1)
{
label->setString("Touch to change armature");
m_armatureIndex = 0;
}
}
//TestArmatureNode
void TestArmatureNode::onEnter()
{
ArmatureTestLayer::onEnter();
auto node = CSLoader::createNode("TestArmatureNode.csb");
addChild(node);
2014-12-23 11:13:05 +08:00
node->setPositionX(Director::getInstance()->getVisibleSize().width * .25f);
}
std::string TestArmatureNode::title() const
{
return "Test Armature Node";
}
std::string TestArmatureNode::subtitle() const
{
return "Csb file loaded";
}