issue #2771: update project setting

This commit is contained in:
boyu0 2013-09-17 14:31:43 +08:00
parent 9f7bf4349c
commit 0a53a12f51
11 changed files with 68 additions and 1099 deletions

View File

@ -16,7 +16,8 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include \
$(LOCAL_PATH)/../../cocos2dx \
$(LOCAL_PATH)/../../cocos2dx/include \
$(LOCAL_PATH)/../../cocos2dx/kazmath/include \
$(LOCAL_PATH)/../../cocos2dx/platform/android
$(LOCAL_PATH)/../../cocos2dx/platform/android \
$(LOCAL_PATH)/../../external/chipmunk/include/chipmunk
LOCAL_CFLAGS += -Wno-psabi
LOCAL_EXPORT_CFLAGS += -Wno-psabi

View File

@ -111,7 +111,6 @@ physics/chipmunk/CCPhysicsContactInfo.cpp \
physics/chipmunk/CCPhysicsJointInfo.cpp \
physics/chipmunk/CCPhysicsShapeInfo.cpp \
physics/chipmunk/CCPhysicsWorldInfo.cpp \
physics/chipmunk/ChipmunkDebugDraw.c \
platform/CCEGLViewProtocol.cpp \
platform/CCFileUtils.cpp \
platform/CCSAXParser.cpp \
@ -165,7 +164,8 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
$(LOCAL_PATH)/platform/android \
$(LOCAL_PATH)/platform/third_party/common/etc \
$(LOCAL_PATH)/platform/third_party/common/s3tc \
$(LOCAL_PATH)/platform/third_party/common/atitc
$(LOCAL_PATH)/platform/third_party/common/atitc \
$(LOCAL_PATH)/../external/chipmunk/include/chipmunk
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
$(LOCAL_PATH)/include \
@ -173,7 +173,8 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) \
$(LOCAL_PATH)/platform/android \
$(LOCAL_PATH)/platform/third_party/common/etc \
$(LOCAL_PATH)/platform/third_party/common/s3tc \
$(LOCAL_PATH)/platform/third_party/common/atitc
$(LOCAL_PATH)/platform/third_party/common/atitc \
$(LOCAL_PATH)/../external/chipmunk/include/chipmunk
LOCAL_LDLIBS := -lGLESv2 \

View File

@ -24,6 +24,8 @@
#include "CCPhysicsBody.h"
#ifdef CC_USE_PHYSICS
#include <algorithm>
#include "CCPhysicsShape.h"
#include "CCPhysicsJoint.h"
#include "CCPhysicsWorld.h"

View File

@ -83,6 +83,36 @@ PhysicsJointPin::~PhysicsJointPin()
}
PhysicsJointFixed::PhysicsJointFixed()
{
}
PhysicsJointFixed::~PhysicsJointFixed()
{
}
PhysicsJointSliding::PhysicsJointSliding()
{
}
PhysicsJointSliding::~PhysicsJointSliding()
{
}
PhysicsJointLimit::PhysicsJointLimit()
{
}
PhysicsJointLimit::~PhysicsJointLimit()
{
}
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
PhysicsBodyInfo* PhysicsJoint::bodyInfo(PhysicsBody* body) const
{

View File

@ -277,6 +277,12 @@ void PhysicsWorld::collisionSeparateCallback(const PhysicsContact& contact)
}
}
void PhysicsWorld::setGravity(Point gravity)
{
_gravity = gravity;
cpSpaceSetGravity(_info->space, PhysicsHelper::point2cpv(_gravity));
}
#elif (CC_PHYSICS_ENGINE == CC_PHYSICS_BOX2D)
#endif

View File

@ -63,7 +63,7 @@ public:
inline void unregisterContactListener() { _listener = nullptr; }
inline Point getGravity() { return _gravity; }
inline void setGravity(Point gravity) { _gravity = gravity; }
void setGravity(Point gravity);
inline bool getDebugDraw() { return _debugDraw; }
inline void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; }

View File

@ -24,6 +24,7 @@
#include "CCPhysicsShapeInfo.h"
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
#include <algorithm>
NS_CC_BEGIN
std::map<cpShape*, PhysicsShapeInfo*> PhysicsShapeInfo::map;
@ -56,7 +57,7 @@ void PhysicsShapeInfo::remove(cpShape* shape)
{
if (shape == nullptr) return;
auto it = find(shapes.begin(), shapes.end(), shape);
auto it = std::find(shapes.begin(), shapes.end(), shape);
if (it != shapes.end())
{
shapes.erase(it);

View File

@ -45,7 +45,6 @@ Classes/DrawPrimitivesTest/DrawPrimitivesTest.cpp \
Classes/EffectsAdvancedTest/EffectsAdvancedTest.cpp \
Classes/EffectsTest/EffectsTest.cpp \
Classes/ExtensionsTest/ExtensionsTest.cpp \
Classes/ExtensionsTest/ArmatureTest/ArmatureScene.cpp \
Classes/ExtensionsTest/CocosBuilderTest/CocosBuilderTest.cpp \
Classes/ExtensionsTest/CocosBuilderTest/AnimationsTest/AnimationsTestLayer.cpp \
Classes/ExtensionsTest/CocosBuilderTest/ButtonTest/ButtonTestLayer.cpp \
@ -60,8 +59,27 @@ Classes/ExtensionsTest/CocoStudioComponentsTest/GameOverScene.cpp \
Classes/ExtensionsTest/CocoStudioComponentsTest/PlayerController.cpp \
Classes/ExtensionsTest/CocoStudioComponentsTest/ProjectileController.cpp \
Classes/ExtensionsTest/CocoStudioComponentsTest/SceneController.cpp \
Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/CocosGUIScene.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UIScene.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UISceneManager.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UIButtonTest/UIButtonTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UIDragPanelTest/UIDragPanelTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UIImageViewTest/UIImageViewTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UILabelAtlasTest/UILabelAtlasTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UILabelBMFontTest/UILabelBMFontTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UILabelTest/UILabelTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UILoadingBarTest/UILoadingBarTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UINodeContainerTest/UINodeContainerTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UIPanelTest/UIPanelTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UISliderTest/UISliderTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UITextAreaTest/UITextAreaTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UITextButtonTest/UITextButtonTest.cpp \
Classes/ExtensionsTest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp \
Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp \
Classes/ExtensionsTest/ControlExtensionTest/CCControlScene.cpp \
Classes/ExtensionsTest/ControlExtensionTest/CCControlSceneManager.cpp \
Classes/ExtensionsTest/ControlExtensionTest/CCControlButtonTest/CCControlButtonTest.cpp \

View File

@ -1,873 +0,0 @@
#include "ArmatureScene.h"
#include "../../testResource.h"
using namespace cocos2d;
using namespace cocos2d::extension;
CCLayer* NextTest();
CCLayer* BackTest();
CCLayer* RestartTest();
static int s_nActionIdx = -1;
CCLayer *CreateLayer(int index)
{
CCLayer *pLayer = NULL;
switch(index)
{
case TEST_DRAGON_BONES_2_0:
pLayer = new TestDragonBones20(); break;
case TEST_COCOSTUDIO_WITH_SKELETON:
pLayer = new TestCSWithSkeleton(); break;
case TEST_COCOSTUDIO_WITHOUT_SKELETON:
pLayer = new TestCSWithoutSkeleton(); break;
case TEST_PERFORMANCE:
pLayer = new TestPerformance(); break;
case TEST_CHANGE_ZORDER:
pLayer = new TestChangeZorder(); break;
case TEST_ANIMATION_EVENT:
pLayer = new TestAnimationEvent(); break;
case TEST_PARTICLE_DISPLAY:
pLayer = new TestParticleDisplay(); break;
case TEST_USE_DIFFERENT_PICTURE:
pLayer = new TestUseMutiplePicture(); break;
case TEST_BCOLLIDER_DETECTOR:
pLayer = new TestColliderDetector(); break;
case TEST_BOUDINGBOX:
pLayer = new TestBoundingBox(); break;
case TEST_ANCHORPOINT:
pLayer = new TestAnchorPoint(); break;
case TEST_ARMATURE_NESTING:
pLayer = new TestArmatureNesting(); break;
default:
break;
}
return pLayer;
}
CCLayer* NextTest()
{
++s_nActionIdx;
s_nActionIdx = s_nActionIdx % TEST_LAYER_COUNT;
CCLayer* pLayer = CreateLayer(s_nActionIdx);
pLayer->autorelease();
return pLayer;
}
CCLayer* BackTest()
{
--s_nActionIdx;
if( s_nActionIdx < 0 )
s_nActionIdx += TEST_LAYER_COUNT;
CCLayer* pLayer = CreateLayer(s_nActionIdx);
pLayer->autorelease();
return pLayer;
}
CCLayer* RestartTest()
{
CCLayer* pLayer = CreateLayer(s_nActionIdx);
pLayer->autorelease();
return pLayer;
}
ArmatureTestScene::ArmatureTestScene(bool bPortrait)
{
TestScene::init();
CCSprite *bg = CCSprite::create("armature/bg.jpg");
bg->setPosition(VisibleRect::center());
float scaleX = VisibleRect::getVisibleRect().size.width / bg->getContentSize().width;
float scaleY = VisibleRect::getVisibleRect().size.height / bg->getContentSize().height;
bg->setScaleX(scaleX);
bg->setScaleY(scaleY);
addChild(bg);
}
void ArmatureTestScene::runThisTest()
{
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/TestBone0.png", "armature/TestBone0.plist", "armature/TestBone.json");
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Cowboy0.png", "armature/Cowboy0.plist", "armature/Cowboy.ExportJson");
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml");
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml");
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml");
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml");
CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml");
s_nActionIdx = -1;
addChild(NextTest());
CCDirector::sharedDirector()->replaceScene(this);
}
void ArmatureTestScene::MainMenuCallback(CCObject* pSender)
{
TestScene::MainMenuCallback(pSender);
removeAllChildren();
CCArmatureDataManager::sharedArmatureDataManager()->purgeArmatureSystem();
}
void ArmatureTestLayer::onEnter()
{
CCLayer::onEnter();
// add title and subtitle
std::string str = title();
const char * pTitle = str.c_str();
CCLabelTTF* label = CCLabelTTF::create(pTitle, "Arial", 18);
label->setColor(ccc3(0, 0, 0));
addChild(label, 1, 10000);
label->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 30) );
std::string strSubtitle = subtitle();
if( ! strSubtitle.empty() )
{
CCLabelTTF* l = CCLabelTTF::create(strSubtitle.c_str(), "Arial", 18);
l->setColor(ccc3(0, 0, 0));
addChild(l, 1, 10001);
l->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y - 60) );
}
// add menu
CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(ArmatureTestLayer::backCallback) );
CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(ArmatureTestLayer::restartCallback) );
CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(ArmatureTestLayer::nextCallback) );
CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);
menu->setPosition(CCPointZero);
item1->setPosition(ccp(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
item2->setPosition(ccp(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
item3->setPosition(ccp(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
addChild(menu, 100);
setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));
}
void ArmatureTestLayer::onExit()
{
}
std::string ArmatureTestLayer::title()
{
return "CSArmature Test Bed";
}
std::string ArmatureTestLayer::subtitle()
{
return "";
}
void ArmatureTestLayer::restartCallback(CCObject* pSender)
{
CCScene* s = new ArmatureTestScene();
s->addChild( RestartTest() );
CCDirector::sharedDirector()->replaceScene(s);
s->release();
}
void ArmatureTestLayer::nextCallback(CCObject* pSender)
{
CCScene* s = new ArmatureTestScene();
s->addChild( NextTest() );
CCDirector::sharedDirector()->replaceScene(s);
s->release();
}
void ArmatureTestLayer::backCallback(CCObject* pSender)
{
CCScene* s = new ArmatureTestScene();
s->addChild( BackTest() );
CCDirector::sharedDirector()->replaceScene(s);
s->release();
}
void ArmatureTestLayer::draw()
{
CCLayer::draw();
}
void TestDragonBones20::onEnter()
{
ArmatureTestLayer::onEnter();
cocos2d::extension::CCArmature *armature = NULL;
armature = cocos2d::extension::CCArmature::create("Dragon");
armature->getAnimation()->playByIndex(1);
armature->getAnimation()->setAnimationScale(0.4f);
armature->setPosition(VisibleRect::center().x, VisibleRect::center().y * 0.3f);
armature->setScale(0.6f);
addChild(armature);
}
std::string TestDragonBones20::title()
{
return "Test Export From DragonBones version 2.0";
}
void TestCSWithSkeleton::onEnter()
{
ArmatureTestLayer::onEnter();
cocos2d::extension::CCArmature *armature = NULL;
armature = cocos2d::extension::CCArmature::create("Cowboy");
armature->getAnimation()->playByIndex(0);
armature->setScale(0.2f);
armature->setPosition(ccp(VisibleRect::center().x, VisibleRect::center().y/*-100*/));
addChild(armature);
}
std::string TestCSWithSkeleton::title()
{
return "Test Export From CocoStudio With Skeleton Effect";
}
void TestCSWithoutSkeleton::onEnter()
{
ArmatureTestLayer::onEnter();
cocos2d::extension::CCArmature *armature = NULL;
armature = cocos2d::extension::CCArmature::create("TestBone");
armature->getAnimation()->playByIndex(0);
armature->setAnchorPoint(ccp(0.5, -0.1));
armature->setScale(0.2f);
armature->setPosition(ccp(VisibleRect::center().x, VisibleRect::center().y-100));
addChild(armature);
}
std::string TestCSWithoutSkeleton::title()
{
return "Test Export From CocoStudio Without Skeleton Effect";
}
TestPerformance::~TestPerformance()
{
}
void TestPerformance::onEnter()
{
ArmatureTestLayer::onEnter();
armatureCount = frames = times = lastTimes = 0;
generated = false;
scheduleUpdate();
}
std::string TestPerformance::title()
{
return "Test Performance";
}
std::string TestPerformance::subtitle()
{
return "Current CCArmature Count : ";
}
void TestPerformance::addArmature(cocos2d::extension::CCArmature *armature)
{
armatureCount++;
addChild(armature, armatureCount);
}
void TestPerformance::update(float delta)
{
frames ++;
times += delta;
if (frames/times > 58)
{
cocos2d::extension::CCArmature *armature = NULL;
armature = new cocos2d::extension::CCArmature();
armature->init("Knight_f/Knight");
armature->getAnimation()->playByIndex(0);
armature->setPosition(50 + armatureCount * 2, 150);
armature->setScale(0.6f);
addArmature(armature);
armature->release();
char pszCount[255];
sprintf(pszCount, "%s %i", subtitle().c_str(), armatureCount);
CCLabelTTF *label = (CCLabelTTF*)getChildByTag(10001);
label->setString(pszCount);
}
}
void TestChangeZorder::onEnter()
{
ArmatureTestLayer::onEnter();
cocos2d::extension::CCArmature *armature = NULL;
currentTag = -1;
armature = cocos2d::extension::CCArmature::create("Knight_f/Knight");
armature->getAnimation()->playByIndex(0);
armature->setPosition(ccp(VisibleRect::center().x, VisibleRect::center().y-100));
++currentTag;
armature->setScale(0.6f);
addChild(armature, currentTag, currentTag);
armature = cocos2d::extension::CCArmature::create("TestBone");
armature->getAnimation()->playByIndex(0);
armature->setScale(0.24f);
armature->setPosition(ccp(VisibleRect::center().x, VisibleRect::center().y-100));
++currentTag;
addChild(armature, currentTag, currentTag);
armature = cocos2d::extension::CCArmature::create("Dragon");
armature->getAnimation()->playByIndex(0);
armature->setPosition(ccp(VisibleRect::center().x , VisibleRect::center().y-100));
++currentTag;
armature->setScale(0.6f);
addChild(armature, currentTag, currentTag);
schedule( schedule_selector(TestChangeZorder::changeZorder), 1);
currentTag = 0;
}
std::string TestChangeZorder::title()
{
return "Test Change ZOrder Of Different CCArmature";
}
void TestChangeZorder::changeZorder(float dt)
{
CCNode *node = getChildByTag(currentTag);
node->setZOrder(CCRANDOM_0_1() * 3);
currentTag ++;
currentTag = currentTag % 3;
}
void TestAnimationEvent::onEnter()
{
ArmatureTestLayer::onEnter();
armature = cocos2d::extension::CCArmature::create("Cowboy");
armature->getAnimation()->play("Fire");
armature->setScaleX(-0.24f);
armature->setScaleY(0.24f);
armature->setPosition(ccp(VisibleRect::left().x + 50, VisibleRect::left().y));
armature->getAnimation()->MovementEventSignal.connect(this, &TestAnimationEvent::animationEvent);
addChild(armature);
}
std::string TestAnimationEvent::title()
{
return "Test CCArmature Animation Event";
}
void TestAnimationEvent::animationEvent(cocos2d::extension::CCArmature *armature, MovementEventType movementType, const char *movementID)
{
std::string id = movementID;
if (movementType == LOOP_COMPLETE)
{
if (id.compare("Fire") == 0)
{
CCActionInterval *actionToRight = CCMoveTo::create(2, ccp(VisibleRect::right().x - 50, VisibleRect::right().y));
armature->stopAllActions();
armature->runAction(CCSequence::create(actionToRight, CCCallFunc::create(this, callfunc_selector(TestAnimationEvent::callback1)), NULL));
armature->getAnimation()->play("Walk");
}
else if (id.compare("FireMax") == 0)
{
CCActionInterval *actionToLeft = CCMoveTo::create(2, ccp(VisibleRect::left().x + 50, VisibleRect::left().y));
armature->stopAllActions();
armature->runAction(CCSequence::create(actionToLeft, CCCallFunc::create(this, callfunc_selector(TestAnimationEvent::callback2)), NULL));
armature->getAnimation()->play("Walk");
}
}
}
void TestAnimationEvent::callback1()
{
armature->runAction(CCScaleTo::create(0.3f, 0.3f, 0.3f));
armature->getAnimation()->play("FireMax", 10);
}
void TestAnimationEvent::callback2()
{
armature->runAction(CCScaleTo::create(0.3f, -0.3f, 0.3f));
armature->getAnimation()->play("Fire", 10);
}
void TestParticleDisplay::onEnter()
{
ArmatureTestLayer::onEnter();
setTouchEnabled(true);
animationID = 0;
armature = cocos2d::extension::CCArmature::create("robot");
armature->getAnimation()->playByIndex(0);
armature->setPosition(VisibleRect::center());
armature->setScale(0.48f);
armature->getAnimation()->setAnimationScale(0.5f);
addChild(armature);
CCParticleSystem *p1 = CCParticleSystemQuad::create("Particles/SmallSun.plist");
CCParticleSystem *p2 = CCParticleSystemQuad::create("Particles/SmallSun.plist");
cocos2d::extension::CCBone *bone = cocos2d::extension::CCBone::create("p1");
bone->addDisplay(p1, 0);
bone->changeDisplayByIndex(0, true);
bone->setIgnoreMovementBoneData(true);
bone->setZOrder(100);
bone->setScale(1.2f);
armature->addBone(bone, "bady-a3");
bone = cocos2d::extension::CCBone::create("p2");
bone->addDisplay(p2, 0);
bone->changeDisplayByIndex(0, true);
bone->setIgnoreMovementBoneData(true);
bone->setZOrder(100);
bone->setScale(1.2f);
armature->addBone(bone, "bady-a30");
}
std::string TestParticleDisplay::title()
{
return "Test Particle Display";
}
std::string TestParticleDisplay::subtitle()
{
return "Touch to change animation";
}
bool TestParticleDisplay::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
++animationID;
animationID = animationID % armature->getAnimation()->getMovementCount();
armature->getAnimation()->playByIndex(animationID);
return false;
}
void TestParticleDisplay::registerWithTouchDispatcher()
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true);
}
void TestUseMutiplePicture::onEnter()
{
ArmatureTestLayer::onEnter();
setTouchEnabled(true);
displayIndex = 0;
armature = cocos2d::extension::CCArmature::create("Knight_f/Knight");
armature->getAnimation()->playByIndex(0);
armature->setPosition(ccp(VisibleRect::left().x+70, VisibleRect::left().y));
armature->setScale(1.2f);
addChild(armature);
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"};
CCSpriteDisplayData displayData;
for (int i = 0; i < 7; i++)
{
displayData.setParam(weapon[i].c_str());
armature->getBone("weapon")->addDisplay(&displayData, i);
}
}
std::string TestUseMutiplePicture::title()
{
return "Test One CCArmature Use Different Picture";
}
std::string TestUseMutiplePicture::subtitle()
{
return "weapon and armature are in different picture";
}
bool TestUseMutiplePicture::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
++displayIndex;
displayIndex = (displayIndex) % 6;
armature->getBone("weapon")->changeDisplayByIndex(displayIndex, true);
return false;
}
void TestUseMutiplePicture::registerWithTouchDispatcher()
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true);
}
#if ENABLE_PHYSICS_BOX2D_DETECT
class Contact
{
public:
b2Fixture *fixtureA;
b2Fixture *fixtureB;
};
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();
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);
}
public:
std::list<Contact> contact_list;
};
#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);
CCBone *bone = (CCBone*)a->data;
bone->getArmature()->setVisible(false);
return 0;
}
void TestColliderDetector::endHit(cpArbiter *arb, cpSpace *space, void *unused)
{
CP_ARBITER_GET_SHAPES(arb, a, b);
CCBone *bone = (CCBone*)a->data;
bone->getArmature()->setVisible(true);
}
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);
}
#endif
TestColliderDetector::~TestColliderDetector()
{
#if ENABLE_PHYSICS_BOX2D_DETECT
CC_SAFE_DELETE(world);
CC_SAFE_DELETE(listener);
CC_SAFE_DELETE(debugDraw);
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
destroyCPBody(armature2->getCPBody());
destroyCPBody(bullet->getCPBody());
cpSpaceFree(space);
#endif
}
void TestColliderDetector::onEnter()
{
ArmatureTestLayer::onEnter();
scheduleUpdate();
armature = cocos2d::extension::CCArmature::create("Cowboy");
armature->getAnimation()->play("FireWithoutBullet");
armature->getAnimation()->setAnimationScale(0.2f);
armature->setScaleX(-0.2f);
armature->setScaleY(0.2f);
armature->setPosition(ccp(VisibleRect::left().x + 70, VisibleRect::left().y));
addChild(armature);
armature2 = cocos2d::extension::CCArmature::create("Cowboy");
armature2->getAnimation()->play("Walk");
armature2->setScaleX(-0.2f);
armature2->setScaleY(0.2f);
armature2->setPosition(ccp(VisibleRect::right().x - 30, VisibleRect::left().y));
addChild(armature2);
bullet = CCPhysicsSprite::createWithSpriteFrameName("25.png");
addChild(bullet);
initWorld();
}
std::string TestColliderDetector::title()
{
return "Test Collider Detector";
}
void TestColliderDetector::draw()
{
#if ENABLE_PHYSICS_BOX2D_DETECT
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
kmGLPushMatrix();
world->DrawDebugData();
kmGLPopMatrix();
#endif
}
void TestColliderDetector::update(float delta)
{
#if ENABLE_PHYSICS_BOX2D_DETECT
armature2->setVisible(true);
#endif
if (armature->getAnimation()->getCurrentFrameIndex() == 9)
{
CCPoint p = armature->getBone("Layer126")->getDisplayRenderNode()->convertToWorldSpaceAR(ccp(0, 0));
bullet->setPosition(ccp(p.x + 60, p.y));
bullet->stopAllActions();
bullet->runAction(CCMoveBy::create(1.5f, ccp(350, 0)));
}
#if ENABLE_PHYSICS_BOX2D_DETECT
world->Step(delta, 0, 0);
for (std::list<Contact>::iterator it = listener->contact_list.begin(); it != listener->contact_list.end(); ++it)
{
Contact &contact = *it;
b2Body *b2a = contact.fixtureA->GetBody();
b2Body *b2b = contact.fixtureB->GetBody();
CCBone *ba = (CCBone *)b2a->GetUserData();
CCBone *bb = (CCBone *)b2b->GetUserData();
bb->getArmature()->setVisible(false);
}
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
cpSpaceStep(space, delta);
#endif
}
void TestColliderDetector::initWorld()
{
#if ENABLE_PHYSICS_BOX2D_DETECT
b2Vec2 noGravity(0, 0);
world = new b2World(noGravity);
world->SetAllowSleeping(true);
listener = new ContactListener();
world->SetContactListener(listener);
debugDraw = new GLESDebugDraw( PT_RATIO );
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( ccp( -100, -100) );
body = world->CreateBody(&bodyDef);
armature2->setB2Body(body);
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
space = cpSpaceNew();
space->gravity = cpv(0, 0);
// Physics debug layer
CCPhysicsDebugNode *debugLayer = CCPhysicsDebugNode::create(space);
this->addChild(debugLayer, INT_MAX);
CCSize 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(INFINITY, INFINITY);
cpSpaceAddBody(space, body);
armature2->setCPBody(body);
shape = body->shapeList_private;
while(shape){
cpShape *next = shape->next_private;
shape->collision_type = eEnemyTag;
shape = next;
}
cpSpaceAddCollisionHandler(space, eEnemyTag, eBulletTag, beginHit, NULL, NULL, endHit, NULL);
#endif
}
void TestBoundingBox::onEnter()
{
ArmatureTestLayer::onEnter();
armature = cocos2d::extension::CCArmature::create("Cowboy");
armature->getAnimation()->playByIndex(0);
armature->setPosition(VisibleRect::center());
armature->setScale(0.2f);
addChild(armature);
}
std::string TestBoundingBox::title()
{
return "Test BoundingBox";
}
void TestBoundingBox::draw()
{
CC_NODE_DRAW_SETUP();
rect = CCRectApplyAffineTransform(armature->boundingBox(), armature->nodeToParentTransform());
ccDrawColor4B(100, 100, 100, 255);
ccDrawRect(rect.origin, ccp(rect.getMaxX(), rect.getMaxY()));
}
void TestAnchorPoint::onEnter()
{
ArmatureTestLayer::onEnter();
for (int i = 0; i<5; i++)
{
cocos2d::extension::CCArmature *armature = cocos2d::extension::CCArmature::create("Cowboy");
armature->getAnimation()->playByIndex(0);
armature->setPosition(VisibleRect::center());
armature->setScale(0.2f);
addChild(armature, 0, i);
}
getChildByTag(0)->setAnchorPoint(ccp(0,0));
getChildByTag(1)->setAnchorPoint(ccp(0,1));
getChildByTag(2)->setAnchorPoint(ccp(1,0));
getChildByTag(3)->setAnchorPoint(ccp(1,1));
getChildByTag(4)->setAnchorPoint(ccp(0.5,0.5));
}
std::string TestAnchorPoint::title()
{
return "Test Set AnchorPoint";
}
void TestArmatureNesting::onEnter()
{
ArmatureTestLayer::onEnter();
setTouchEnabled(true);
armature = cocos2d::extension::CCArmature::create("cyborg");
armature->getAnimation()->playByIndex(1);
armature->setPosition(VisibleRect::center());
armature->setScale(1.2f);
armature->getAnimation()->setAnimationScale(0.4f);
addChild(armature);
weaponIndex = 0;
}
std::string TestArmatureNesting::title()
{
return "Test CCArmature Nesting";
}
bool TestArmatureNesting::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
++weaponIndex;
weaponIndex = weaponIndex % 4;
armature->getBone("armInside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex);
armature->getBone("armOutside")->getChildArmature()->getAnimation()->playByIndex(weaponIndex);
return false;
}
void TestArmatureNesting::registerWithTouchDispatcher()
{
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, INT_MIN+1, true);
}

View File

@ -1,217 +0,0 @@
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
#include "cocos-ext.h"
#include "../../VisibleRect.h"
#include "../../testBasic.h"
#if ENABLE_PHYSICS_BOX2D_DETECT
#include "../../Box2DTestBed/GLES-Render.h"
#include "Box2D/Box2D.h"
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
#include "chipmunk.h"
#endif
class ArmatureTestScene : public TestScene
{
public:
ArmatureTestScene(bool bPortrait = false);
virtual void runThisTest();
// The CallBack for back to the main menu scene
virtual void MainMenuCallback(CCObject* pSender);
};
enum {
TEST_COCOSTUDIO_WITH_SKELETON = 0,
TEST_COCOSTUDIO_WITHOUT_SKELETON,
TEST_DRAGON_BONES_2_0,
TEST_PERFORMANCE,
TEST_CHANGE_ZORDER,
TEST_ANIMATION_EVENT,
TEST_PARTICLE_DISPLAY,
TEST_USE_DIFFERENT_PICTURE,
TEST_BCOLLIDER_DETECTOR,
TEST_BOUDINGBOX,
TEST_ANCHORPOINT,
TEST_ARMATURE_NESTING,
TEST_LAYER_COUNT
};
class ArmatureTestLayer : public CCLayer
{
public:
virtual void onEnter();
virtual void onExit();
virtual std::string title();
virtual std::string subtitle();
void restartCallback(CCObject* pSender);
void nextCallback(CCObject* pSender);
void backCallback(CCObject* pSender);
virtual void draw();
};
class TestDragonBones20 : public ArmatureTestLayer
{
public:
virtual void onEnter();
virtual std::string title();
};
class TestCSWithSkeleton : public ArmatureTestLayer
{
virtual void onEnter();
virtual std::string title();
};
class TestCSWithoutSkeleton : public ArmatureTestLayer
{
virtual void onEnter();
virtual std::string title();
};
class TestPerformance : public ArmatureTestLayer
{
public:
~TestPerformance();
virtual void onEnter();
virtual std::string title();
virtual std::string subtitle();
virtual void addArmature(cocos2d::extension::CCArmature *armature);
void update(float delta);
int armatureCount;
int frames;
float times;
float lastTimes;
bool generated;
};
class TestChangeZorder : public ArmatureTestLayer
{
virtual void onEnter();
virtual std::string title();
void changeZorder(float dt);
int currentTag;
};
class TestAnimationEvent : public ArmatureTestLayer, public sigslot::has_slots<>
{
public:
virtual void onEnter();
virtual std::string title();
void animationEvent(cocos2d::extension::CCArmature *armature, cocos2d::extension::MovementEventType movementType, const char *movementID);
void callback1();
void callback2();
cocos2d::extension::CCArmature *armature;
};
class TestUseMutiplePicture : public ArmatureTestLayer
{
virtual void onEnter();
virtual std::string title();
virtual std::string subtitle();
virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
virtual void registerWithTouchDispatcher();
int displayIndex;
cocos2d::extension::CCArmature *armature;
};
class TestParticleDisplay : public ArmatureTestLayer
{
virtual void onEnter();
virtual std::string title();
virtual std::string subtitle();
virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
virtual void registerWithTouchDispatcher();
int animationID;
cocos2d::extension::CCArmature *armature;
};
#if ENABLE_PHYSICS_BOX2D_DETECT
class ContactListener;
#endif
class TestColliderDetector : public ArmatureTestLayer, public sigslot::has_slots<>
{
public:
~TestColliderDetector();
virtual void onEnter();
virtual std::string title();
virtual void draw();
virtual void update(float delta);
void initWorld();
cocos2d::extension::CCArmature *armature;
cocos2d::extension::CCArmature *armature2;
cocos2d::extension::CCPhysicsSprite *bullet;
#if ENABLE_PHYSICS_BOX2D_DETECT
b2World *world;
ContactListener *listener;
GLESDebugDraw *debugDraw;
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
cpSpace *space;
static int beginHit(cpArbiter *arb, cpSpace *space, void *unused);
static void endHit(cpArbiter *arb, cpSpace *space, void *unused);
void destroyCPBody(cpBody *body);
#endif
};
class TestBoundingBox : public ArmatureTestLayer
{
public:
virtual void onEnter();
virtual std::string title();
virtual void draw();
cocos2d::extension::CCArmature *armature;
CCRect rect;
};
class TestAnchorPoint : public ArmatureTestLayer
{
public:
virtual void onEnter();
virtual std::string title();
};
class TestArmatureNesting : public ArmatureTestLayer
{
public:
virtual void onEnter();
virtual std::string title();
virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
virtual void registerWithTouchDispatcher();
cocos2d::extension::CCArmature *armature;
int weaponIndex;
};
#endif // __HELLOWORLD_SCENE_H__

View File

@ -1,7 +1,7 @@
#include "CocosGUIScene.h"
#include "UISceneManager.h"
//#include "CocosGUIExamplesRegisterScene.h"
#include "ExtensionsTest.h"
#include "../ExtensionsTest.h"
const char* gui_scene_names[2] =
{