Merge pull request #788 from minggo/NodeTest

rename CocosNodeTest to NodeTest and SC
This commit is contained in:
minggo 2012-03-20 22:53:43 -07:00
commit e8861f80bf
5 changed files with 476 additions and 430 deletions

View File

@ -25,7 +25,6 @@ tests/BugsTest/Bug-458/Bug-458.cpp \
tests/BugsTest/Bug-458/QuestionContainerSprite.cpp \ tests/BugsTest/Bug-458/QuestionContainerSprite.cpp \
tests/ClickAndMoveTest/ClickAndMoveTest.cpp \ tests/ClickAndMoveTest/ClickAndMoveTest.cpp \
tests/CocosDenshionTest/CocosDenshionTest.cpp \ tests/CocosDenshionTest/CocosDenshionTest.cpp \
tests/CocosNodeTest/CocosNodeTest.cpp \
tests/CurlTest/CurlTest.cpp \ tests/CurlTest/CurlTest.cpp \
tests/CurrentLanguageTest/CurrentLanguageTest.cpp \ tests/CurrentLanguageTest/CurrentLanguageTest.cpp \
tests/DirectorTest/DirectorTest.cpp \ tests/DirectorTest/DirectorTest.cpp \
@ -40,6 +39,7 @@ tests/IntervalTest/IntervalTest.cpp \
tests/KeypadTest/KeypadTest.cpp \ tests/KeypadTest/KeypadTest.cpp \
tests/LabelTest/LabelTest.cpp \ tests/LabelTest/LabelTest.cpp \
tests/LayerTest/LayerTest.cpp \ tests/LayerTest/LayerTest.cpp \
tests/NodeTest/NodeTest.cpp \
tests/TextInputTest/TextInputTest.cpp \ tests/TextInputTest/TextInputTest.cpp \
tests/MenuTest/MenuTest.cpp \ tests/MenuTest/MenuTest.cpp \
tests/MotionStreakTest/MotionStreakTest.cpp \ tests/MotionStreakTest/MotionStreakTest.cpp \

View File

@ -335,18 +335,6 @@
> >
</File> </File>
</Filter> </Filter>
<Filter
Name="CocosNodeTest"
>
<File
RelativePath="..\tests\CocosNodeTest\CocosNodeTest.cpp"
>
</File>
<File
RelativePath="..\tests\CocosNodeTest\CocosNodeTest.h"
>
</File>
</Filter>
<Filter <Filter
Name="TouchesTest" Name="TouchesTest"
> >
@ -850,6 +838,14 @@
<Filter <Filter
Name="NodeTest" Name="NodeTest"
> >
<File
RelativePath="..\tests\NodeTest\NodeTest.cpp"
>
</File>
<File
RelativePath="..\tests\NodeTest\NodeTest.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="ActionsProgressTest" Name="ActionsProgressTest"

View File

@ -1,28 +1,28 @@
#include "CocosNodeTest.h" #include "NodeTest.h"
#include "../testResource.h" #include "../testResource.h"
enum enum
{ {
kTagSprite1 = 1, kTagSprite1 = 1,
kTagSprite2 = 2, kTagSprite2 = 2,
kTagSprite3 = 3, kTagSprite3 = 3,
kTagSlider, kTagSlider,
}; };
CCLayer* nextCocosNodeAction(); CCLayer* nextCocosNodeAction();
CCLayer* backCocosNodeAction(); CCLayer* backCocosNodeAction();
CCLayer* restartCocosNodeAction(); CCLayer* restartCocosNodeAction();
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// TestCocosNodeDemo // TestCocosNodeDemo
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
static int sceneIdx = -1; static int sceneIdx = -1;
#define MAX_LAYER 12 #define MAX_LAYER 14
CCLayer* createCocosNodeLayer(int nIndex) CCLayer* createCocosNodeLayer(int nIndex)
{ {
@ -40,6 +40,8 @@ CCLayer* createCocosNodeLayer(int nIndex)
case 9: return new CameraOrbitTest(); case 9: return new CameraOrbitTest();
case 10: return new CameraZoomTest(); case 10: return new CameraZoomTest();
case 11: return new ConvertToNode(); case 11: return new ConvertToNode();
case 12: return new NodeOpaqueTest();
case 13: return new NodeNonOpaqueTest();
} }
return NULL; return NULL;
@ -75,17 +77,17 @@ CCLayer* restartCocosNodeAction()
pLayer->autorelease(); pLayer->autorelease();
return pLayer; return pLayer;
} }
TestCocosNodeDemo::TestCocosNodeDemo(void) TestCocosNodeDemo::TestCocosNodeDemo(void)
{ {
} }
TestCocosNodeDemo::~TestCocosNodeDemo(void) TestCocosNodeDemo::~TestCocosNodeDemo(void)
{ {
} }
std::string TestCocosNodeDemo::title() std::string TestCocosNodeDemo::title()
{ {
return "No title"; return "No title";
@ -103,15 +105,15 @@ void TestCocosNodeDemo::onEnter()
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 32); CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 32);
addChild(label, 1); addChild(label, 10);
label->setPosition( CCPointMake(s.width/2, s.height-50) ); label->setPosition( CCPointMake(s.width/2, s.height-50) );
std::string strSubtitle = subtitle(); std::string strSubtitle = subtitle();
if( ! strSubtitle.empty() ) if( ! strSubtitle.empty() )
{ {
CCLabelTTF* l = CCLabelTTF::labelWithString(strSubtitle.c_str(), "Thonburi", 16); CCLabelTTF* l = CCLabelTTF::labelWithString(strSubtitle.c_str(), "Thonburi", 16);
addChild(l, 1); addChild(l, 1);
l->setPosition( CCPointMake(s.width/2, s.height-80) ); l->setPosition( CCPointMake(s.width/2, s.height-80) );
} }
CCMenuItemImage *item1 = CCMenuItemImage::itemWithNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(TestCocosNodeDemo::backCallback) ); CCMenuItemImage *item1 = CCMenuItemImage::itemWithNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(TestCocosNodeDemo::backCallback) );
@ -125,7 +127,7 @@ void TestCocosNodeDemo::onEnter()
item2->setPosition( CCPointMake( s.width/2, 30) ); item2->setPosition( CCPointMake( s.width/2, 30) );
item3->setPosition( CCPointMake( s.width/2 + 100,30) ); item3->setPosition( CCPointMake( s.width/2 + 100,30) );
addChild(menu, 1); addChild(menu, 11);
} }
void TestCocosNodeDemo::restartCallback(CCObject* pSender) void TestCocosNodeDemo::restartCallback(CCObject* pSender)
@ -152,16 +154,16 @@ void TestCocosNodeDemo::backCallback(CCObject* pSender)
CCDirector::sharedDirector()->replaceScene(s); CCDirector::sharedDirector()->replaceScene(s);
s->release(); s->release();
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// Test2 // Test2
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
void Test2::onEnter() void Test2::onEnter()
{ {
TestCocosNodeDemo::onEnter(); TestCocosNodeDemo::onEnter();
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
@ -206,7 +208,7 @@ std::string Test2::title()
return "anchorPoint and children"; return "anchorPoint and children";
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// Test4 // Test4
@ -215,8 +217,8 @@ std::string Test2::title()
#define SID_DELAY2 1 #define SID_DELAY2 1
#define SID_DELAY4 2 #define SID_DELAY4 2
Test4::Test4() Test4::Test4()
{ {
CCSprite *sp1 = CCSprite::spriteWithFile(s_pPathSister1); CCSprite *sp1 = CCSprite::spriteWithFile(s_pPathSister1);
CCSprite *sp2 = CCSprite::spriteWithFile(s_pPathSister2); CCSprite *sp2 = CCSprite::spriteWithFile(s_pPathSister2);
@ -227,8 +229,8 @@ Test4::Test4()
addChild(sp2, 0, 3); addChild(sp2, 0, 3);
schedule( schedule_selector(Test4::delay2), 2.0f); schedule( schedule_selector(Test4::delay2), 2.0f);
schedule( schedule_selector(Test4::delay4), 4.0f); schedule( schedule_selector(Test4::delay4), 4.0f);
} }
void Test4::delay2(ccTime dt) void Test4::delay2(ccTime dt)
{ {
@ -248,14 +250,14 @@ std::string Test4::title()
return "tags"; return "tags";
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// Test5 // Test5
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
Test5::Test5() Test5::Test5()
{ {
CCSprite* sp1 = CCSprite::spriteWithFile(s_pPathSister1); CCSprite* sp1 = CCSprite::spriteWithFile(s_pPathSister1);
CCSprite* sp2 = CCSprite::spriteWithFile(s_pPathSister2); CCSprite* sp2 = CCSprite::spriteWithFile(s_pPathSister2);
@ -277,8 +279,8 @@ Test5::Test5()
sp1->runAction(forever); sp1->runAction(forever);
sp2->runAction(forever2); sp2->runAction(forever2);
schedule( schedule_selector(Test5::addAndRemove), 2.0f); schedule( schedule_selector(Test5::addAndRemove), 2.0f);
} }
void Test5::addAndRemove(ccTime dt) void Test5::addAndRemove(ccTime dt)
{ {
@ -302,14 +304,14 @@ std::string Test5::title()
{ {
return "remove and cleanup"; return "remove and cleanup";
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// Test6 // Test6
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
Test6::Test6() Test6::Test6()
{ {
CCSprite* sp1 = CCSprite::spriteWithFile(s_pPathSister1); CCSprite* sp1 = CCSprite::spriteWithFile(s_pPathSister1);
CCSprite* sp11 = CCSprite::spriteWithFile(s_pPathSister1); CCSprite* sp11 = CCSprite::spriteWithFile(s_pPathSister1);
@ -338,8 +340,8 @@ Test6::Test6()
sp2->runAction(forever2); sp2->runAction(forever2);
sp21->runAction(forever21); sp21->runAction(forever21);
schedule( schedule_selector(Test6::addAndRemove), 2.0f); schedule( schedule_selector(Test6::addAndRemove), 2.0f);
} }
void Test6::addAndRemove(ccTime dt) void Test6::addAndRemove(ccTime dt)
{ {
@ -370,8 +372,8 @@ std::string Test6::title()
// StressTest1 // StressTest1
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
StressTest1::StressTest1() StressTest1::StressTest1()
{ {
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
CCSprite *sp1 = CCSprite::spriteWithFile(s_pPathSister1); CCSprite *sp1 = CCSprite::spriteWithFile(s_pPathSister1);
@ -379,8 +381,8 @@ StressTest1::StressTest1()
sp1->setPosition( CCPointMake(s.width/2, s.height/2) ); sp1->setPosition( CCPointMake(s.width/2, s.height/2) );
schedule( schedule_selector(StressTest1::shouldNotCrash), 1.0f); schedule( schedule_selector(StressTest1::shouldNotCrash), 1.0f);
} }
void StressTest1::shouldNotCrash(ccTime dt) void StressTest1::shouldNotCrash(ccTime dt)
{ {
@ -423,8 +425,8 @@ std::string StressTest1::title()
// StressTest2 // StressTest2
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
StressTest2::StressTest2() StressTest2::StressTest2()
{ {
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLayer* sublayer = CCLayer::node(); CCLayer* sublayer = CCLayer::node();
@ -449,9 +451,9 @@ StressTest2::StressTest2()
sublayer->addChild(fire, 2); sublayer->addChild(fire, 2);
schedule(schedule_selector(StressTest2::shouldNotLeak), 6.0f); schedule(schedule_selector(StressTest2::shouldNotLeak), 6.0f);
addChild(sublayer, 0, kTagSprite1); addChild(sublayer, 0, kTagSprite1);
} }
void StressTest2::shouldNotLeak(ccTime dt) void StressTest2::shouldNotLeak(ccTime dt)
{ {
@ -471,8 +473,8 @@ std::string StressTest2::title()
// SchedulerTest1 // SchedulerTest1
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
SchedulerTest1::SchedulerTest1() SchedulerTest1::SchedulerTest1()
{ {
CCLayer*layer = CCLayer::node(); CCLayer*layer = CCLayer::node();
//UXLOG("retain count after init is %d", layer->retainCount()); // 1 //UXLOG("retain count after init is %d", layer->retainCount()); // 1
@ -483,8 +485,8 @@ SchedulerTest1::SchedulerTest1()
//UXLOG("retain count after schedule is %d", layer->retainCount()); // 3 : (object-c viersion), but win32 version is still 2, because CCTimer class don't save target. //UXLOG("retain count after schedule is %d", layer->retainCount()); // 3 : (object-c viersion), but win32 version is still 2, because CCTimer class don't save target.
layer->unschedule(schedule_selector(SchedulerTest1::doSomething)); layer->unschedule(schedule_selector(SchedulerTest1::doSomething));
//UXLOG("retain count after unschedule is %d", layer->retainCount()); // STILL 3! (win32 is '2') //UXLOG("retain count after unschedule is %d", layer->retainCount()); // STILL 3! (win32 is '2')
} }
void SchedulerTest1::doSomething(ccTime dt) void SchedulerTest1::doSomething(ccTime dt)
{ {
@ -501,352 +503,384 @@ std::string SchedulerTest1::title()
// NodeToWorld // NodeToWorld
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
NodeToWorld::NodeToWorld() NodeToWorld::NodeToWorld()
{ {
// //
// This code tests that nodeToParent works OK: // This code tests that nodeToParent works OK:
// - It tests different anchor Points // - It tests different anchor Points
// - It tests different children anchor points // - It tests different children anchor points
CCSprite *back = CCSprite::spriteWithFile(s_back3); CCSprite *back = CCSprite::spriteWithFile(s_back3);
addChild( back, -10); addChild( back, -10);
back->setAnchorPoint( CCPointMake(0,0) ); back->setAnchorPoint( CCPointMake(0,0) );
CCSize backSize = back->getContentSize(); CCSize backSize = back->getContentSize();
CCMenuItem *item = CCMenuItemImage::itemWithNormalImage(s_PlayNormal, s_PlaySelect); CCMenuItem *item = CCMenuItemImage::itemWithNormalImage(s_PlayNormal, s_PlaySelect);
CCMenu *menu = CCMenu::menuWithItems(item, NULL); CCMenu *menu = CCMenu::menuWithItems(item, NULL);
menu->alignItemsVertically(); menu->alignItemsVertically();
menu->setPosition( CCPointMake(backSize.width/2, backSize.height/2)); menu->setPosition( CCPointMake(backSize.width/2, backSize.height/2));
back->addChild(menu); back->addChild(menu);
CCActionInterval* rot = CCRotateBy::actionWithDuration(5, 360); CCActionInterval* rot = CCRotateBy::actionWithDuration(5, 360);
CCAction* fe = CCRepeatForever::actionWithAction( rot); CCAction* fe = CCRepeatForever::actionWithAction( rot);
item->runAction( fe ); item->runAction( fe );
CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(200,0)); CCActionInterval* move = CCMoveBy::actionWithDuration(3, CCPointMake(200,0));
CCActionInterval* move_back = move->reverse(); CCActionInterval* move_back = move->reverse();
CCFiniteTimeAction* seq = CCSequence::actions( move, move_back, NULL); CCFiniteTimeAction* seq = CCSequence::actions( move, move_back, NULL);
CCAction* fe2 = CCRepeatForever::actionWithAction((CCActionInterval*)seq); CCAction* fe2 = CCRepeatForever::actionWithAction((CCActionInterval*)seq);
back->runAction(fe2); back->runAction(fe2);
} }
std::string NodeToWorld::title() std::string NodeToWorld::title()
{ {
return "nodeToParent transform"; return "nodeToParent transform";
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// CameraOrbitTest // CameraOrbitTest
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
void CameraOrbitTest::onEnter() void CameraOrbitTest::onEnter()
{ {
TestCocosNodeDemo::onEnter(); TestCocosNodeDemo::onEnter();
CCDirector::sharedDirector()->setProjection(kCCDirectorProjection3D); CCDirector::sharedDirector()->setProjection(kCCDirectorProjection3D);
} }
void CameraOrbitTest::onExit() void CameraOrbitTest::onExit()
{ {
CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D); CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D);
TestCocosNodeDemo::onExit(); TestCocosNodeDemo::onExit();
} }
CameraOrbitTest::CameraOrbitTest() CameraOrbitTest::CameraOrbitTest()
{ {
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
CCSprite *p = CCSprite::spriteWithFile(s_back3); CCSprite *p = CCSprite::spriteWithFile(s_back3);
addChild( p, 0); addChild( p, 0);
p->setPosition( CCPointMake(s.width/2, s.height/2) ); p->setPosition( CCPointMake(s.width/2, s.height/2) );
p->setOpacity( 128 ); p->setOpacity( 128 );
CCSprite* sprite; CCSprite* sprite;
CCOrbitCamera* orbit; CCOrbitCamera* orbit;
CCCamera* cam; CCCamera* cam;
CCSize ss; CCSize ss;
// LEFT // LEFT
s = p->getContentSize(); s = p->getContentSize();
sprite = CCSprite::spriteWithFile(s_pPathGrossini); sprite = CCSprite::spriteWithFile(s_pPathGrossini);
sprite->setScale(0.5f); sprite->setScale(0.5f);
p->addChild(sprite, 0); p->addChild(sprite, 0);
sprite->setPosition( CCPointMake(s.width/4*1, s.height/2) ); sprite->setPosition( CCPointMake(s.width/4*1, s.height/2) );
cam = sprite->getCamera(); cam = sprite->getCamera();
orbit = CCOrbitCamera::actionWithDuration(2, 1, 0, 0, 360, 0, 0); orbit = CCOrbitCamera::actionWithDuration(2, 1, 0, 0, 360, 0, 0);
sprite->runAction( CCRepeatForever::actionWithAction( orbit ) ); sprite->runAction( CCRepeatForever::actionWithAction( orbit ) );
// CENTER // CENTER
sprite = CCSprite::spriteWithFile(s_pPathGrossini); sprite = CCSprite::spriteWithFile(s_pPathGrossini);
sprite->setScale( 1.0f ); sprite->setScale( 1.0f );
p->addChild(sprite, 0); p->addChild(sprite, 0);
sprite->setPosition( CCPointMake(s.width/4*2, s.height/2) ); sprite->setPosition( CCPointMake(s.width/4*2, s.height/2) );
orbit = CCOrbitCamera::actionWithDuration(2, 1, 0, 0, 360, 45, 0); orbit = CCOrbitCamera::actionWithDuration(2, 1, 0, 0, 360, 45, 0);
sprite->runAction( CCRepeatForever::actionWithAction( orbit ) ); sprite->runAction( CCRepeatForever::actionWithAction( orbit ) );
// RIGHT // RIGHT
sprite = CCSprite::spriteWithFile(s_pPathGrossini); sprite = CCSprite::spriteWithFile(s_pPathGrossini);
sprite->setScale( 2.0f ); sprite->setScale( 2.0f );
p->addChild(sprite, 0); p->addChild(sprite, 0);
sprite->setPosition( CCPointMake(s.width/4*3, s.height/2) ); sprite->setPosition( CCPointMake(s.width/4*3, s.height/2) );
ss = sprite->getContentSize(); ss = sprite->getContentSize();
orbit = CCOrbitCamera::actionWithDuration(2, 1, 0, 0, 360, 90, -45), orbit = CCOrbitCamera::actionWithDuration(2, 1, 0, 0, 360, 90, -45),
sprite->runAction( CCRepeatForever::actionWithAction(orbit) ); sprite->runAction( CCRepeatForever::actionWithAction(orbit) );
// PARENT // PARENT
orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 90); orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 90);
p->runAction( CCRepeatForever::actionWithAction( orbit ) ); p->runAction( CCRepeatForever::actionWithAction( orbit ) );
setScale( 1 ); setScale( 1 );
} }
std::string CameraOrbitTest::title() std::string CameraOrbitTest::title()
{ {
return "Camera Orbit test"; return "Camera Orbit test";
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// CameraZoomTest // CameraZoomTest
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
void CameraZoomTest::onEnter() void CameraZoomTest::onEnter()
{ {
TestCocosNodeDemo::onEnter(); TestCocosNodeDemo::onEnter();
CCDirector::sharedDirector()->setProjection(kCCDirectorProjection3D); CCDirector::sharedDirector()->setProjection(kCCDirectorProjection3D);
} }
void CameraZoomTest::onExit() void CameraZoomTest::onExit()
{ {
CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D); CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D);
TestCocosNodeDemo::onExit(); TestCocosNodeDemo::onExit();
} }
CameraZoomTest::CameraZoomTest() CameraZoomTest::CameraZoomTest()
{ {
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
CCSprite *sprite; CCSprite *sprite;
CCCamera *cam; CCCamera *cam;
// LEFT // LEFT
sprite = CCSprite::spriteWithFile(s_pPathGrossini); sprite = CCSprite::spriteWithFile(s_pPathGrossini);
addChild( sprite, 0); addChild( sprite, 0);
sprite->setPosition( CCPointMake(s.width/4*1, s.height/2) ); sprite->setPosition( CCPointMake(s.width/4*1, s.height/2) );
cam = sprite->getCamera(); cam = sprite->getCamera();
cam->setEyeXYZ(0, 0, 415); cam->setEyeXYZ(0, 0, 415/2);
cam->setCenterXYZ(0, 0, 0);
// CENTER
sprite = CCSprite::spriteWithFile(s_pPathGrossini); // CENTER
addChild( sprite, 0, 40); sprite = CCSprite::spriteWithFile(s_pPathGrossini);
sprite->setPosition(CCPointMake(s.width/4*2, s.height/2)); addChild( sprite, 0, 40);
// cam = [sprite camera); sprite->setPosition(CCPointMake(s.width/4*2, s.height/2));
// [cam setEyeX:0 eyeY:0 eyeZ:415/2);
// RIGHT
// RIGHT sprite = CCSprite::spriteWithFile(s_pPathGrossini);
sprite = CCSprite::spriteWithFile(s_pPathGrossini); addChild( sprite, 0, 20);
addChild( sprite, 0, 20); sprite->setPosition(CCPointMake(s.width/4*3, s.height/2));
sprite->setPosition(CCPointMake(s.width/4*3, s.height/2));
// cam = [sprite camera); m_z = 0;
// [cam setEyeX:0 eyeY:0 eyeZ:-485); scheduleUpdate();
// [cam setCenterX:0 centerY:0 centerZ:0); }
m_z = 0; void CameraZoomTest::update(ccTime dt)
scheduleUpdate(); {
} CCNode *sprite;
CCCamera *cam;
void CameraZoomTest::update(ccTime dt)
{ m_z += dt * 100;
CCNode *sprite;
CCCamera *cam; sprite = getChildByTag(20);
cam = sprite->getCamera();
m_z += dt * 100; cam->setEyeXYZ(0, 0, m_z);
sprite = getChildByTag(20); sprite = getChildByTag(40);
cam = sprite->getCamera(); cam = sprite->getCamera();
cam->setEyeXYZ(0, 0, m_z); cam->setEyeXYZ(0, 0, -m_z);
}
sprite = getChildByTag(40);
cam = sprite->getCamera(); std::string CameraZoomTest::title()
cam->setEyeXYZ(0, 0, m_z); {
} return "Camera Zoom test";
}
std::string CameraZoomTest::title()
{
return "Camera Zoom test";
}
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// CameraCenterTest // CameraCenterTest
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
CameraCenterTest::CameraCenterTest() CameraCenterTest::CameraCenterTest()
{ {
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
CCSprite *sprite; CCSprite *sprite;
CCOrbitCamera *orbit; CCOrbitCamera *orbit;
// LEFT-TOP // LEFT-TOP
sprite = new CCSprite();//::node(); sprite = CCSprite::spriteWithFile("Images/white-512x512.png");
sprite->init(); addChild( sprite, 0);
addChild( sprite, 0); sprite->setPosition(CCPointMake(s.width/5*1, s.height/5*1));
sprite->setPosition(CCPointMake(s.width/5*1, s.height/5*1)); sprite->setColor(ccRED);
sprite->setColor(ccRED); sprite->setTextureRect(CCRectMake(0, 0, 120, 50));
sprite->setTextureRect(CCRectMake(0, 0, 120, 50)); orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0);
orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0); sprite->runAction(CCRepeatForever::actionWithAction( orbit ));
sprite->runAction(CCRepeatForever::actionWithAction( orbit )); // [sprite setAnchorPoint: CCPointMake(0,1));
sprite->release();
// [sprite setAnchorPoint: CCPointMake(0,1));
// LEFT-BOTTOM
sprite = CCSprite::spriteWithFile("Images/white-512x512.png");
// LEFT-BOTTOM addChild( sprite, 0, 40);
sprite = new CCSprite();//::node(); sprite->setPosition(CCPointMake(s.width/5*1, s.height/5*4));
sprite->init(); sprite->setColor(ccBLUE);
addChild( sprite, 0, 40); sprite->setTextureRect(CCRectMake(0, 0, 120, 50));
sprite->setPosition(CCPointMake(s.width/5*1, s.height/5*4)); orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0);
sprite->setColor(ccBLUE); sprite->runAction(CCRepeatForever::actionWithAction( orbit ));
sprite->setTextureRect(CCRectMake(0, 0, 120, 50));
orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0);
sprite->runAction(CCRepeatForever::actionWithAction( orbit )); // RIGHT-TOP
sprite->release(); sprite = CCSprite::spriteWithFile("Images/white-512x512.png");
// [sprite setAnchorPoint: CCPointMake(0,0)); addChild( sprite, 0);
sprite->setPosition(CCPointMake(s.width/5*4, s.height/5*1));
sprite->setColor(ccYELLOW);
// RIGHT-TOP sprite->setTextureRect(CCRectMake(0, 0, 120, 50));
sprite = new CCSprite();//::node(); orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0);
sprite->init(); sprite->runAction(CCRepeatForever::actionWithAction( orbit) );
addChild( sprite, 0);
sprite->setPosition(CCPointMake(s.width/5*4, s.height/5*1));
sprite->setColor(ccYELLOW); // RIGHT-BOTTOM
sprite->setTextureRect(CCRectMake(0, 0, 120, 50)); sprite = CCSprite::spriteWithFile("Images/white-512x512.png");
orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0); addChild( sprite, 0, 40);
sprite->runAction(CCRepeatForever::actionWithAction( orbit) ); sprite->setPosition(CCPointMake(s.width/5*4, s.height/5*4));
sprite->release(); sprite->setColor(ccGREEN);
// [sprite setAnchorPoint: CCPointMake(1,1)); sprite->setTextureRect(CCRectMake(0, 0, 120, 50));
orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0);
sprite->runAction( CCRepeatForever::actionWithAction( orbit ) );
// RIGHT-BOTTOM
sprite = new CCSprite();//::node(); // CENTER
sprite->init(); sprite = CCSprite::spriteWithFile("Images/white-512x512.png");
addChild( sprite, 0, 40); addChild( sprite, 0, 40);
sprite->setPosition(CCPointMake(s.width/5*4, s.height/5*4)); sprite->setPosition(CCPointMake(s.width/2, s.height/2));
sprite->setColor(ccGREEN); sprite->setColor(ccWHITE);
sprite->setTextureRect(CCRectMake(0, 0, 120, 50)); sprite->setTextureRect(CCRectMake(0, 0, 120, 50));
orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0); orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0);
sprite->runAction( CCRepeatForever::actionWithAction( orbit ) ); sprite->runAction(CCRepeatForever::actionWithAction( orbit ) );
sprite->release(); }
// [sprite setAnchorPoint: CCPointMake(1,0));
std::string CameraCenterTest::title()
// CENTER {
sprite = new CCSprite(); return "Camera Center test";
sprite->init(); }
addChild( sprite, 0, 40);
sprite->setPosition(CCPointMake(s.width/2, s.height/2)); std::string CameraCenterTest::subtitle()
sprite->setColor(ccWHITE); {
sprite->setTextureRect(CCRectMake(0, 0, 120, 50)); return "Sprites should rotate at the same speed";
orbit = CCOrbitCamera::actionWithDuration(10, 1, 0, 0, 360, 0, 0); }
sprite->runAction(CCRepeatForever::actionWithAction( orbit ) );
sprite->release();
// [sprite setAnchorPoint: CCPointMake(0.5f, 0.5f));
}
std::string CameraCenterTest::title()
{
return "Camera Center test";
}
std::string CameraCenterTest::subtitle()
{
return "Sprites should rotate at the same speed";
}
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// ConvertToNode // ConvertToNode
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
ConvertToNode::ConvertToNode() ConvertToNode::ConvertToNode()
{ {
setIsTouchEnabled(true); setIsTouchEnabled(true);
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
CCRotateBy* rotate = CCRotateBy::actionWithDuration(10, 360); CCRotateBy* rotate = CCRotateBy::actionWithDuration(10, 360);
CCRepeatForever* action = CCRepeatForever::actionWithAction(rotate); CCRepeatForever* action = CCRepeatForever::actionWithAction(rotate);
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++)
{ {
CCSprite *sprite = CCSprite::spriteWithFile("Images/grossini.png"); CCSprite *sprite = CCSprite::spriteWithFile("Images/grossini.png");
sprite->setPosition(ccp( s.width/4*(i+1), s.height/2)); sprite->setPosition(ccp( s.width/4*(i+1), s.height/2));
CCSprite *point = CCSprite::spriteWithFile("Images/r1.png"); CCSprite *point = CCSprite::spriteWithFile("Images/r1.png");
point->setScale(0.25f); point->setScale(0.25f);
point->setPosition(sprite->getPosition()); point->setPosition(sprite->getPosition());
addChild(point, 10, 100 + i); addChild(point, 10, 100 + i);
switch(i) switch(i)
{ {
case 0: case 0:
sprite->setAnchorPoint(CCPointZero); sprite->setAnchorPoint(CCPointZero);
break; break;
case 1: case 1:
sprite->setAnchorPoint(ccp(0.5f, 0.5f)); sprite->setAnchorPoint(ccp(0.5f, 0.5f));
break; break;
case 2: case 2:
sprite->setAnchorPoint(ccp(1,1)); sprite->setAnchorPoint(ccp(1,1));
break; break;
} }
point->setPosition(sprite->getPosition()); point->setPosition(sprite->getPosition());
CCRepeatForever* copy = (CCRepeatForever*) action->copy(); CCRepeatForever* copy = (CCRepeatForever*) action->copy();
copy->autorelease(); copy->autorelease();
sprite->runAction(copy); sprite->runAction(copy);
addChild(sprite, i); addChild(sprite, i);
} }
} }
void ConvertToNode::ccTouchesEnded(CCSet* touches, CCEvent *event) void ConvertToNode::ccTouchesEnded(CCSet* touches, CCEvent *event)
{ {
for( CCSetIterator it = touches->begin(); it != touches->end(); ++it) for( CCSetIterator it = touches->begin(); it != touches->end(); ++it)
{ {
CCTouch* touch = (CCTouch*)(*it); CCTouch* touch = (CCTouch*)(*it);
CCPoint location = touch->locationInView(); CCPoint location = touch->locationInView();
location = CCDirector::sharedDirector()->convertToGL(location); location = CCDirector::sharedDirector()->convertToGL(location);
for( int i = 0; i < 3; i++) for( int i = 0; i < 3; i++)
{ {
CCNode *node = getChildByTag(100+i); CCNode *node = getChildByTag(100+i);
CCPoint p1, p2; CCPoint p1, p2;
p1 = node->convertToNodeSpaceAR(location); p1 = node->convertToNodeSpaceAR(location);
p2 = node->convertToNodeSpace(location); p2 = node->convertToNodeSpace(location);
CCLOG("AR: x=%.2f, y=%.2f -- Not AR: x=%.2f, y=%.2f", p1.x, p1.y, p2.x, p2.y); CCLOG("AR: x=%.2f, y=%.2f -- Not AR: x=%.2f, y=%.2f", p1.x, p1.y, p2.x, p2.y);
} }
} }
} }
std::string ConvertToNode::title() std::string ConvertToNode::title()
{ {
return "Convert To Node Space"; return "Convert To Node Space";
} }
std::string ConvertToNode::subtitle() std::string ConvertToNode::subtitle()
{ {
return "testing convertToNodeSpace / AR. Touch and see console"; return "testing convertToNodeSpace / AR. Touch and see console";
} }
void CocosNodeTestScene::runThisTest() /// NodeOpaqueTest
{
CCLayer* pLayer = nextCocosNodeAction(); NodeOpaqueTest::NodeOpaqueTest()
addChild(pLayer); {
CCSprite *background = NULL;
CCDirector::sharedDirector()->replaceScene(this);
} for (int i = 0; i < 50; i++)
{
background = CCSprite::spriteWithFile("Images/background1.png");
background->setGLServerState((ccGLServerState)(background->getGLServerState() & (~CC_GL_BLEND)));
background->setAnchorPoint(CCPointZero);
addChild(background);
}
}
std::string NodeOpaqueTest::title()
{
return "Node Opaque Test";
}
std::string NodeOpaqueTest::subtitle()
{
return "Node rendered with GL_BLEND disabled";
}
/// NodeNonOpaqueTest
NodeNonOpaqueTest::NodeNonOpaqueTest()
{
CCSprite *background = NULL;
for (int i = 0; i < 50; i++)
{
background = CCSprite::spriteWithFile("Images/background1.jpg");
background->setGLServerState((ccGLServerState)(background->getGLServerState() | CC_GL_BLEND));
background->setAnchorPoint(CCPointZero);
addChild(background);
}
}
std::string NodeNonOpaqueTest::title()
{
return "Node Non Opaque Test";
}
std::string NodeNonOpaqueTest::subtitle()
{
return "Node rendered with GL_BLEND enabled";
}
void CocosNodeTestScene::runThisTest()
{
CCLayer* pLayer = nextCocosNodeAction();
addChild(pLayer);
CCDirector::sharedDirector()->replaceScene(this);
}

View File

@ -1,15 +1,15 @@
#ifndef _COCOSNODE_TEST_H_ #ifndef _NODE_TEST_H_
#define _COCOSNODE_TEST_H_ #define _NODE_TEST_H_
////----#include "cocos2d.h" ////----#include "cocos2d.h"
#include "../testBasic.h" #include "../testBasic.h"
class TestCocosNodeDemo : public CCLayer class TestCocosNodeDemo : public CCLayer
{ {
public: public:
TestCocosNodeDemo(void); TestCocosNodeDemo(void);
~TestCocosNodeDemo(void); ~TestCocosNodeDemo(void);
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual void onEnter(); virtual void onEnter();
@ -21,14 +21,14 @@ public:
class Test2 : public TestCocosNodeDemo class Test2 : public TestCocosNodeDemo
{ {
public: public:
virtual void onEnter(); virtual void onEnter();
virtual std::string title(); virtual std::string title();
}; };
class Test4 : public TestCocosNodeDemo class Test4 : public TestCocosNodeDemo
{ {
public: public:
Test4(); Test4();
void delay2(ccTime dt); void delay2(ccTime dt);
void delay4(ccTime dt); void delay4(ccTime dt);
@ -38,7 +38,7 @@ public:
class Test5 : public TestCocosNodeDemo class Test5 : public TestCocosNodeDemo
{ {
public: public:
Test5(); Test5();
void addAndRemove(ccTime dt); void addAndRemove(ccTime dt);
@ -47,7 +47,7 @@ public:
class Test6 : public TestCocosNodeDemo class Test6 : public TestCocosNodeDemo
{ {
public: public:
Test6(); Test6();
void addAndRemove(ccTime dt); void addAndRemove(ccTime dt);
@ -58,7 +58,7 @@ class StressTest1 : public TestCocosNodeDemo
{ {
void shouldNotCrash(ccTime dt); void shouldNotCrash(ccTime dt);
void removeMe(CCNode* node); void removeMe(CCNode* node);
public: public:
StressTest1(); StressTest1();
virtual std::string title(); virtual std::string title();
@ -67,7 +67,7 @@ public:
class StressTest2 : public TestCocosNodeDemo class StressTest2 : public TestCocosNodeDemo
{ {
void shouldNotLeak(ccTime dt); void shouldNotLeak(ccTime dt);
public: public:
StressTest2(); StressTest2();
virtual std::string title(); virtual std::string title();
@ -75,7 +75,7 @@ public:
class SchedulerTest1 : public TestCocosNodeDemo class SchedulerTest1 : public TestCocosNodeDemo
{ {
public: public:
SchedulerTest1(); SchedulerTest1();
void doSomething(ccTime dt); void doSomething(ccTime dt);
@ -84,14 +84,14 @@ public:
class NodeToWorld : public TestCocosNodeDemo class NodeToWorld : public TestCocosNodeDemo
{ {
public: public:
NodeToWorld(); NodeToWorld();
virtual std::string title(); virtual std::string title();
}; };
class CameraOrbitTest : public TestCocosNodeDemo class CameraOrbitTest : public TestCocosNodeDemo
{ {
public: public:
CameraOrbitTest(); CameraOrbitTest();
virtual void onEnter(); virtual void onEnter();
@ -102,7 +102,7 @@ public:
class CameraZoomTest : public TestCocosNodeDemo class CameraZoomTest : public TestCocosNodeDemo
{ {
float m_z; float m_z;
public: public:
CameraZoomTest(); CameraZoomTest();
void update(ccTime dt); void update(ccTime dt);
@ -114,7 +114,7 @@ public:
class CameraCenterTest : public TestCocosNodeDemo class CameraCenterTest : public TestCocosNodeDemo
{ {
public: public:
CameraCenterTest(); CameraCenterTest();
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
@ -129,6 +129,22 @@ public:
virtual std::string subtitle(); virtual std::string subtitle();
}; };
class NodeOpaqueTest : public TestCocosNodeDemo
{
public:
NodeOpaqueTest();
virtual std::string title();
virtual std::string subtitle();
};
class NodeNonOpaqueTest : public TestCocosNodeDemo
{
public:
NodeNonOpaqueTest();
virtual std::string title();
virtual std::string subtitle();
};
class CocosNodeTestScene : public TestScene class CocosNodeTestScene : public TestScene
{ {
public: public:

View File

@ -11,7 +11,6 @@
#include "ActionsEaseTest/ActionsEaseTest.h" #include "ActionsEaseTest/ActionsEaseTest.h"
#include "MotionStreakTest/MotionStreakTest.h" #include "MotionStreakTest/MotionStreakTest.h"
#include "DrawPrimitivesTest/DrawPrimitivesTest.h" #include "DrawPrimitivesTest/DrawPrimitivesTest.h"
#include "CocosNodeTest/CocosNodeTest.h"
#include "TouchesTest/TouchesTest.h" #include "TouchesTest/TouchesTest.h"
#include "MenuTest/MenuTest.h" #include "MenuTest/MenuTest.h"
#include "ActionManagerTest/ActionManagerTest.h" #include "ActionManagerTest/ActionManagerTest.h"
@ -45,6 +44,7 @@
#include "FontTest/FontTest.h" #include "FontTest/FontTest.h"
#include "CurrentLanguageTest/CurrentLanguageTest.h" #include "CurrentLanguageTest/CurrentLanguageTest.h"
#include "TextureCacheTest/TextureCacheTest.h" #include "TextureCacheTest/TextureCacheTest.h"
#include "NodeTest/NodeTest.h"
#if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE) #if (CC_TARGET_PLATFORM != CC_PLATFORM_MARMALADE)
#include "ChipmunkTest/cocos2dChipmunkDemo.h" #include "ChipmunkTest/cocos2dChipmunkDemo.h"
@ -117,7 +117,7 @@ const std::string g_aTestNames[TESTS_COUNT] = {
"ActionsEaseTest", "ActionsEaseTest",
"MotionStreakTest", "MotionStreakTest",
"DrawPrimitivesTest", "DrawPrimitivesTest",
"CocosNodeTest", "NodeTest",
"TouchesTest", "TouchesTest",
"MenuTest", "MenuTest",
"ActionManagerTest", "ActionManagerTest",