2012-03-21 13:36:24 +08:00
# include "NodeTest.h"
# include "../testResource.h"
2010-08-26 15:09:02 +08:00
enum
{
2012-04-19 14:35:52 +08:00
kTagSprite1 = 1 ,
kTagSprite2 = 2 ,
kTagSprite3 = 3 ,
kTagSlider ,
2012-03-21 13:36:24 +08:00
} ;
2011-07-08 15:57:46 +08:00
CCLayer * nextCocosNodeAction ( ) ;
CCLayer * backCocosNodeAction ( ) ;
2012-03-21 13:36:24 +08:00
CCLayer * restartCocosNodeAction ( ) ;
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// TestCocosNodeDemo
//
//------------------------------------------------------------------
2012-03-21 13:36:24 +08:00
static int sceneIdx = - 1 ;
2012-04-19 14:35:52 +08:00
# define MAX_LAYER 14
2010-08-26 15:09:02 +08:00
CCLayer * createCocosNodeLayer ( int nIndex )
{
2012-04-19 14:35:52 +08:00
switch ( nIndex )
{
case 0 : return new CameraCenterTest ( ) ;
case 1 : return new Test2 ( ) ;
case 2 : return new Test4 ( ) ;
case 3 : return new Test5 ( ) ;
case 4 : return new Test6 ( ) ;
case 5 : return new StressTest1 ( ) ;
case 6 : return new StressTest2 ( ) ;
case 7 : return new NodeToWorld ( ) ;
case 8 : return new SchedulerTest1 ( ) ;
case 9 : return new CameraOrbitTest ( ) ;
case 10 : return new CameraZoomTest ( ) ;
case 11 : return new ConvertToNode ( ) ;
case 12 : return new NodeOpaqueTest ( ) ;
case 13 : return new NodeNonOpaqueTest ( ) ;
}
return NULL ;
2010-08-26 15:09:02 +08:00
}
CCLayer * nextCocosNodeAction ( )
{
2012-04-19 14:35:52 +08:00
sceneIdx + + ;
sceneIdx = sceneIdx % MAX_LAYER ;
2010-08-26 15:09:02 +08:00
2012-04-19 14:35:52 +08:00
CCLayer * pLayer = createCocosNodeLayer ( sceneIdx ) ;
pLayer - > autorelease ( ) ;
2010-08-26 15:09:02 +08:00
2012-04-19 14:35:52 +08:00
return pLayer ;
2010-08-26 15:09:02 +08:00
}
CCLayer * backCocosNodeAction ( )
{
2012-04-19 14:35:52 +08:00
sceneIdx - - ;
int total = MAX_LAYER ;
if ( sceneIdx < 0 )
sceneIdx + = total ;
CCLayer * pLayer = createCocosNodeLayer ( sceneIdx ) ;
pLayer - > autorelease ( ) ;
2010-08-26 15:09:02 +08:00
2012-04-19 14:35:52 +08:00
return pLayer ;
2010-08-26 15:09:02 +08:00
}
CCLayer * restartCocosNodeAction ( )
{
2012-04-19 14:35:52 +08:00
CCLayer * pLayer = createCocosNodeLayer ( sceneIdx ) ;
pLayer - > autorelease ( ) ;
2010-08-26 15:09:02 +08:00
2012-04-19 14:35:52 +08:00
return pLayer ;
2012-03-21 13:36:24 +08:00
}
TestCocosNodeDemo : : TestCocosNodeDemo ( void )
{
}
TestCocosNodeDemo : : ~ TestCocosNodeDemo ( void )
{
}
2010-08-26 15:09:02 +08:00
std : : string TestCocosNodeDemo : : title ( )
{
2012-04-19 14:35:52 +08:00
return " No title " ;
2010-08-26 15:09:02 +08:00
}
std : : string TestCocosNodeDemo : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " " ;
2010-08-26 15:09:02 +08:00
}
void TestCocosNodeDemo : : onEnter ( )
{
2013-06-07 08:12:28 +08:00
BaseTest : : onEnter ( ) ;
2010-08-26 15:09:02 +08:00
}
2011-03-07 17:11:57 +08:00
void TestCocosNodeDemo : : restartCallback ( CCObject * pSender )
2010-08-26 15:09:02 +08:00
{
2012-06-14 15:13:16 +08:00
CCScene * s = new CocosNodeTestScene ( ) ; //CCScene::create();
2012-04-19 14:35:52 +08:00
s - > addChild ( restartCocosNodeAction ( ) ) ;
2010-08-26 15:09:02 +08:00
2012-04-19 14:35:52 +08:00
CCDirector : : sharedDirector ( ) - > replaceScene ( s ) ;
2010-09-13 17:19:49 +08:00
s - > release ( ) ;
2010-08-26 15:09:02 +08:00
}
2011-03-07 17:11:57 +08:00
void TestCocosNodeDemo : : nextCallback ( CCObject * pSender )
2010-08-26 15:09:02 +08:00
{
2012-06-14 15:13:16 +08:00
CCScene * s = new CocosNodeTestScene ( ) ; //CCScene::create();
2012-04-19 14:35:52 +08:00
s - > addChild ( nextCocosNodeAction ( ) ) ;
CCDirector : : sharedDirector ( ) - > replaceScene ( s ) ;
2010-09-13 17:19:49 +08:00
s - > release ( ) ;
2010-08-26 15:09:02 +08:00
}
2011-03-07 17:11:57 +08:00
void TestCocosNodeDemo : : backCallback ( CCObject * pSender )
2010-08-26 15:09:02 +08:00
{
2012-06-14 15:13:16 +08:00
CCScene * s = new CocosNodeTestScene ( ) ; //CCScene::create();
2012-04-19 14:35:52 +08:00
s - > addChild ( backCocosNodeAction ( ) ) ;
CCDirector : : sharedDirector ( ) - > replaceScene ( s ) ;
2010-09-13 17:19:49 +08:00
s - > release ( ) ;
2010-08-26 15:09:02 +08:00
}
2012-03-21 13:36:24 +08:00
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// Test2
//
//------------------------------------------------------------------
2012-03-21 13:36:24 +08:00
void Test2 : : onEnter ( )
{
2012-04-19 14:35:52 +08:00
TestCocosNodeDemo : : onEnter ( ) ;
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-06-14 15:13:16 +08:00
CCSprite * sp1 = CCSprite : : create ( s_pPathSister1 ) ;
CCSprite * sp2 = CCSprite : : create ( s_pPathSister2 ) ;
CCSprite * sp3 = CCSprite : : create ( s_pPathSister1 ) ;
CCSprite * sp4 = CCSprite : : create ( s_pPathSister2 ) ;
2012-04-19 14:35:52 +08:00
2012-10-23 17:48:50 +08:00
sp1 - > setPosition ( ccp ( 100 , s . height / 2 ) ) ;
sp2 - > setPosition ( ccp ( 380 , s . height / 2 ) ) ;
2012-04-19 14:35:52 +08:00
addChild ( sp1 ) ;
addChild ( sp2 ) ;
sp3 - > setScale ( 0.25f ) ;
sp4 - > setScale ( 0.25f ) ;
sp1 - > addChild ( sp3 ) ;
sp2 - > addChild ( sp4 ) ;
2012-06-14 15:13:16 +08:00
CCActionInterval * a1 = CCRotateBy : : create ( 2 , 360 ) ;
CCActionInterval * a2 = CCScaleBy : : create ( 2 , 2 ) ;
2012-04-19 14:35:52 +08:00
2012-12-10 14:12:56 +08:00
CCAction * action1 = CCRepeatForever : : create ( CCSequence : : create ( a1 , a2 , a2 - > reverse ( ) , NULL ) ) ;
2012-06-14 15:13:16 +08:00
CCAction * action2 = CCRepeatForever : : create (
2012-12-10 14:12:56 +08:00
CCSequence : : create (
( CCActionInterval * ) ( a1 - > copy ( ) - > autorelease ( ) ) ,
( CCActionInterval * ) ( a2 - > copy ( ) - > autorelease ( ) ) ,
a2 - > reverse ( ) ,
NULL )
2012-04-19 14:35:52 +08:00
) ;
2012-10-23 17:48:50 +08:00
sp2 - > setAnchorPoint ( ccp ( 0 , 0 ) ) ;
2012-04-19 14:35:52 +08:00
sp1 - > runAction ( action1 ) ;
sp2 - > runAction ( action2 ) ;
2010-08-26 15:09:02 +08:00
}
std : : string Test2 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " anchorPoint and children " ;
2010-08-26 15:09:02 +08:00
}
2012-03-21 13:36:24 +08:00
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// Test4
//
//------------------------------------------------------------------
2012-04-19 14:35:52 +08:00
# define SID_DELAY2 1
# define SID_DELAY4 2
2010-08-26 15:09:02 +08:00
2012-03-21 13:36:24 +08:00
Test4 : : Test4 ( )
{
2012-06-14 15:13:16 +08:00
CCSprite * sp1 = CCSprite : : create ( s_pPathSister1 ) ;
CCSprite * sp2 = CCSprite : : create ( s_pPathSister2 ) ;
2012-04-19 14:35:52 +08:00
2012-10-23 17:48:50 +08:00
sp1 - > setPosition ( ccp ( 100 , 160 ) ) ;
sp2 - > setPosition ( ccp ( 380 , 160 ) ) ;
2012-04-19 14:35:52 +08:00
addChild ( sp1 , 0 , 2 ) ;
addChild ( sp2 , 0 , 3 ) ;
schedule ( schedule_selector ( Test4 : : delay2 ) , 2.0f ) ;
schedule ( schedule_selector ( Test4 : : delay4 ) , 4.0f ) ;
2012-03-21 13:36:24 +08:00
}
2010-08-26 15:09:02 +08:00
2012-06-08 13:55:28 +08:00
void Test4 : : delay2 ( float dt )
2010-08-26 15:09:02 +08:00
{
2012-04-19 14:35:52 +08:00
CCSprite * node = ( CCSprite * ) ( getChildByTag ( 2 ) ) ;
2012-06-14 15:13:16 +08:00
CCAction * action1 = CCRotateBy : : create ( 1 , 360 ) ;
2012-04-19 14:35:52 +08:00
node - > runAction ( action1 ) ;
2010-08-26 15:09:02 +08:00
}
2012-06-08 13:55:28 +08:00
void Test4 : : delay4 ( float dt )
2010-08-26 15:09:02 +08:00
{
2012-04-19 14:35:52 +08:00
unschedule ( schedule_selector ( Test4 : : delay4 ) ) ;
removeChildByTag ( 3 , false ) ;
2010-08-26 15:09:02 +08:00
}
std : : string Test4 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " tags " ;
2010-08-26 15:09:02 +08:00
}
2012-03-21 13:36:24 +08:00
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// Test5
//
//------------------------------------------------------------------
2012-03-21 13:36:24 +08:00
Test5 : : Test5 ( )
{
2012-06-14 15:13:16 +08:00
CCSprite * sp1 = CCSprite : : create ( s_pPathSister1 ) ;
CCSprite * sp2 = CCSprite : : create ( s_pPathSister2 ) ;
2012-04-19 14:35:52 +08:00
2012-10-23 17:48:50 +08:00
sp1 - > setPosition ( ccp ( 100 , 160 ) ) ;
sp2 - > setPosition ( ccp ( 380 , 160 ) ) ;
2012-04-19 14:35:52 +08:00
2012-06-14 15:13:16 +08:00
CCRotateBy * rot = CCRotateBy : : create ( 2 , 360 ) ;
2012-04-19 14:35:52 +08:00
CCActionInterval * rot_back = rot - > reverse ( ) ;
2012-12-10 14:12:56 +08:00
CCAction * forever = CCRepeatForever : : create ( CCSequence : : create ( rot , rot_back , NULL ) ) ;
2012-04-19 14:35:52 +08:00
CCAction * forever2 = ( CCAction * ) ( forever - > copy ( ) - > autorelease ( ) ) ;
forever - > setTag ( 101 ) ;
forever2 - > setTag ( 102 ) ;
addChild ( sp1 , 0 , kTagSprite1 ) ;
addChild ( sp2 , 0 , kTagSprite2 ) ;
sp1 - > runAction ( forever ) ;
sp2 - > runAction ( forever2 ) ;
schedule ( schedule_selector ( Test5 : : addAndRemove ) , 2.0f ) ;
2012-03-21 13:36:24 +08:00
}
2010-08-26 15:09:02 +08:00
2012-06-08 13:55:28 +08:00
void Test5 : : addAndRemove ( float dt )
2010-08-26 15:09:02 +08:00
{
2012-04-19 14:35:52 +08:00
CCNode * sp1 = getChildByTag ( kTagSprite1 ) ;
CCNode * sp2 = getChildByTag ( kTagSprite2 ) ;
2010-08-26 15:09:02 +08:00
2012-04-19 14:35:52 +08:00
sp1 - > retain ( ) ;
sp2 - > retain ( ) ;
removeChild ( sp1 , false ) ;
removeChild ( sp2 , true ) ;
addChild ( sp1 , 0 , kTagSprite1 ) ;
addChild ( sp2 , 0 , kTagSprite2 ) ;
sp1 - > release ( ) ;
sp2 - > release ( ) ;
2010-08-26 15:09:02 +08:00
}
std : : string Test5 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " remove and cleanup " ;
2010-08-26 15:09:02 +08:00
}
2012-03-21 13:36:24 +08:00
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// Test6
//
//------------------------------------------------------------------
2012-03-21 13:36:24 +08:00
Test6 : : Test6 ( )
{
2012-06-14 15:13:16 +08:00
CCSprite * sp1 = CCSprite : : create ( s_pPathSister1 ) ;
CCSprite * sp11 = CCSprite : : create ( s_pPathSister1 ) ;
2012-04-19 14:35:52 +08:00
2012-06-14 15:13:16 +08:00
CCSprite * sp2 = CCSprite : : create ( s_pPathSister2 ) ;
CCSprite * sp21 = CCSprite : : create ( s_pPathSister2 ) ;
2012-04-19 14:35:52 +08:00
2012-10-23 17:48:50 +08:00
sp1 - > setPosition ( ccp ( 100 , 160 ) ) ;
sp2 - > setPosition ( ccp ( 380 , 160 ) ) ;
2012-04-19 14:35:52 +08:00
2012-06-14 15:13:16 +08:00
CCActionInterval * rot = CCRotateBy : : create ( 2 , 360 ) ;
2012-04-19 14:35:52 +08:00
CCActionInterval * rot_back = rot - > reverse ( ) ;
2012-12-10 14:12:56 +08:00
CCAction * forever1 = CCRepeatForever : : create ( CCSequence : : create ( rot , rot_back , NULL ) ) ;
2012-04-19 14:35:52 +08:00
CCAction * forever11 = ( CCAction * ) ( forever1 - > copy ( ) - > autorelease ( ) ) ;
CCAction * forever2 = ( CCAction * ) ( forever1 - > copy ( ) - > autorelease ( ) ) ;
CCAction * forever21 = ( CCAction * ) ( forever1 - > copy ( ) - > autorelease ( ) ) ;
addChild ( sp1 , 0 , kTagSprite1 ) ;
sp1 - > addChild ( sp11 ) ;
addChild ( sp2 , 0 , kTagSprite2 ) ;
sp2 - > addChild ( sp21 ) ;
sp1 - > runAction ( forever1 ) ;
sp11 - > runAction ( forever11 ) ;
sp2 - > runAction ( forever2 ) ;
sp21 - > runAction ( forever21 ) ;
schedule ( schedule_selector ( Test6 : : addAndRemove ) , 2.0f ) ;
2012-03-21 13:36:24 +08:00
}
2010-08-26 15:09:02 +08:00
2012-06-08 13:55:28 +08:00
void Test6 : : addAndRemove ( float dt )
2010-08-26 15:09:02 +08:00
{
2012-04-19 14:35:52 +08:00
CCNode * sp1 = getChildByTag ( kTagSprite1 ) ;
CCNode * sp2 = getChildByTag ( kTagSprite2 ) ;
2010-08-26 15:09:02 +08:00
2012-04-19 14:35:52 +08:00
sp1 - > retain ( ) ;
sp2 - > retain ( ) ;
removeChild ( sp1 , false ) ;
removeChild ( sp2 , true ) ;
addChild ( sp1 , 0 , kTagSprite1 ) ;
addChild ( sp2 , 0 , kTagSprite2 ) ;
sp1 - > release ( ) ;
sp2 - > release ( ) ;
2010-08-26 15:09:02 +08:00
}
std : : string Test6 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " remove/cleanup with children " ;
2010-08-26 15:09:02 +08:00
}
//------------------------------------------------------------------
//
// StressTest1
//
//------------------------------------------------------------------
2012-03-21 13:36:24 +08:00
StressTest1 : : StressTest1 ( )
{
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2010-08-26 15:09:02 +08:00
2012-06-14 15:13:16 +08:00
CCSprite * sp1 = CCSprite : : create ( s_pPathSister1 ) ;
2012-04-19 14:35:52 +08:00
addChild ( sp1 , 0 , kTagSprite1 ) ;
2012-10-23 17:48:50 +08:00
sp1 - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
2010-08-26 15:09:02 +08:00
2012-04-19 14:35:52 +08:00
schedule ( schedule_selector ( StressTest1 : : shouldNotCrash ) , 1.0f ) ;
2012-03-21 13:36:24 +08:00
}
2010-08-26 15:09:02 +08:00
2012-06-08 13:55:28 +08:00
void StressTest1 : : shouldNotCrash ( float dt )
2010-08-26 15:09:02 +08:00
{
2012-04-19 14:35:52 +08:00
unschedule ( schedule_selector ( StressTest1 : : shouldNotCrash ) ) ;
2010-08-26 15:09:02 +08:00
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2010-08-26 15:09:02 +08:00
2012-04-19 14:35:52 +08:00
// if the node has timers, it crashes
2012-06-14 15:13:16 +08:00
CCNode * explosion = CCParticleSun : : create ( ) ;
2012-04-19 14:35:52 +08:00
( ( CCParticleSun * ) explosion ) - > setTexture ( CCTextureCache : : sharedTextureCache ( ) - > addImage ( " Images/fire.png " ) ) ;
// if it doesn't, it works Ok.
2012-06-14 15:13:16 +08:00
// CocosNode *explosion = [Sprite create:@"grossinis_sister2.png");
2010-08-26 15:09:02 +08:00
2012-10-23 17:48:50 +08:00
explosion - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
2012-04-19 14:35:52 +08:00
2012-06-14 15:13:16 +08:00
runAction ( CCSequence : : create (
CCRotateBy : : create ( 2 , 360 ) ,
CCCallFuncN : : create ( this , callfuncN_selector ( StressTest1 : : removeMe ) ) ,
2012-04-19 14:35:52 +08:00
NULL ) ) ;
addChild ( explosion ) ;
2010-08-26 15:09:02 +08:00
}
// remove
void StressTest1 : : removeMe ( CCNode * node )
2012-04-19 14:35:52 +08:00
{
2013-02-28 16:41:39 +08:00
getParent ( ) - > removeChild ( node , true ) ;
2012-04-19 14:35:52 +08:00
nextCallback ( this ) ;
2010-08-26 15:09:02 +08:00
}
std : : string StressTest1 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " stress test #1: no crashes " ;
2010-08-26 15:09:02 +08:00
}
//------------------------------------------------------------------
//
// StressTest2
//
//------------------------------------------------------------------
2012-03-21 13:36:24 +08:00
StressTest2 : : StressTest2 ( )
{
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-06-14 15:13:16 +08:00
CCLayer * sublayer = CCLayer : : create ( ) ;
2012-04-19 14:35:52 +08:00
2012-06-14 15:13:16 +08:00
CCSprite * sp1 = CCSprite : : create ( s_pPathSister1 ) ;
2012-10-23 17:48:50 +08:00
sp1 - > setPosition ( ccp ( 80 , s . height / 2 ) ) ;
2012-04-19 14:35:52 +08:00
2012-10-23 17:48:50 +08:00
CCActionInterval * move = CCMoveBy : : create ( 3 , ccp ( 350 , 0 ) ) ;
2012-06-14 15:13:16 +08:00
CCActionInterval * move_ease_inout3 = CCEaseInOut : : create ( ( CCActionInterval * ) ( move - > copy ( ) - > autorelease ( ) ) , 2.0f ) ;
2012-04-19 14:35:52 +08:00
CCActionInterval * move_ease_inout_back3 = move_ease_inout3 - > reverse ( ) ;
2012-12-10 14:12:56 +08:00
CCSequence * seq3 = CCSequence : : create ( move_ease_inout3 , move_ease_inout_back3 , NULL ) ;
sp1 - > runAction ( CCRepeatForever : : create ( seq3 ) ) ;
2012-04-19 14:35:52 +08:00
sublayer - > addChild ( sp1 , 1 ) ;
2012-06-14 15:13:16 +08:00
CCParticleFire * fire = CCParticleFire : : create ( ) ;
2012-04-19 14:35:52 +08:00
fire - > setTexture ( CCTextureCache : : sharedTextureCache ( ) - > addImage ( " Images/fire.png " ) ) ;
2012-10-23 17:48:50 +08:00
fire - > setPosition ( ccp ( 80 , s . height / 2 - 50 ) ) ;
2012-04-19 14:35:52 +08:00
CCActionInterval * copy_seq3 = ( CCActionInterval * ) ( seq3 - > copy ( ) - > autorelease ( ) ) ;
2012-06-14 15:13:16 +08:00
fire - > runAction ( CCRepeatForever : : create ( copy_seq3 ) ) ;
2012-04-19 14:35:52 +08:00
sublayer - > addChild ( fire , 2 ) ;
schedule ( schedule_selector ( StressTest2 : : shouldNotLeak ) , 6.0f ) ;
addChild ( sublayer , 0 , kTagSprite1 ) ;
2012-03-21 13:36:24 +08:00
}
2010-08-26 15:09:02 +08:00
2012-06-08 13:55:28 +08:00
void StressTest2 : : shouldNotLeak ( float dt )
2010-08-26 15:09:02 +08:00
{
2012-04-19 14:35:52 +08:00
unschedule ( schedule_selector ( StressTest2 : : shouldNotLeak ) ) ;
CCLayer * sublayer = ( CCLayer * ) getChildByTag ( kTagSprite1 ) ;
sublayer - > removeAllChildrenWithCleanup ( true ) ;
2010-08-26 15:09:02 +08:00
}
std : : string StressTest2 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " stress test #2: no leaks " ;
2010-08-26 15:09:02 +08:00
}
//------------------------------------------------------------------
//
// SchedulerTest1
//
//------------------------------------------------------------------
2012-03-21 13:36:24 +08:00
SchedulerTest1 : : SchedulerTest1 ( )
{
2012-06-14 15:13:16 +08:00
CCLayer * layer = CCLayer : : create ( ) ;
2013-03-03 10:32:09 +08:00
//CCLOG("retain count after init is %d", layer->retainCount()); // 1
2012-04-19 14:35:52 +08:00
addChild ( layer , 0 ) ;
2013-03-03 10:32:09 +08:00
//CCLOG("retain count after addChild is %d", layer->retainCount()); // 2
2012-04-19 14:35:52 +08:00
layer - > schedule ( schedule_selector ( SchedulerTest1 : : doSomething ) ) ;
2013-03-03 10:32:09 +08:00
//CCLOG("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.
2012-04-19 14:35:52 +08:00
layer - > unschedule ( schedule_selector ( SchedulerTest1 : : doSomething ) ) ;
2013-03-03 10:32:09 +08:00
//CCLOG("retain count after unschedule is %d", layer->retainCount()); // STILL 3! (win32 is '2')
2012-03-21 13:36:24 +08:00
}
2010-08-26 15:09:02 +08:00
2012-06-08 13:55:28 +08:00
void SchedulerTest1 : : doSomething ( float dt )
2010-08-26 15:09:02 +08:00
{
}
std : : string SchedulerTest1 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " cocosnode scheduler test #1 " ;
2010-08-26 15:09:02 +08:00
}
//------------------------------------------------------------------
//
// NodeToWorld
//
//------------------------------------------------------------------
2012-03-21 13:36:24 +08:00
NodeToWorld : : NodeToWorld ( )
{
2012-04-19 14:35:52 +08:00
//
// This code tests that nodeToParent works OK:
// - It tests different anchor Points
// - It tests different children anchor points
2012-06-14 15:13:16 +08:00
CCSprite * back = CCSprite : : create ( s_back3 ) ;
2012-04-19 14:35:52 +08:00
addChild ( back , - 10 ) ;
2012-10-23 17:48:50 +08:00
back - > setAnchorPoint ( ccp ( 0 , 0 ) ) ;
2012-04-19 14:35:52 +08:00
CCSize backSize = back - > getContentSize ( ) ;
2012-06-14 15:13:16 +08:00
CCMenuItem * item = CCMenuItemImage : : create ( s_PlayNormal , s_PlaySelect ) ;
CCMenu * menu = CCMenu : : create ( item , NULL ) ;
2012-04-19 14:35:52 +08:00
menu - > alignItemsVertically ( ) ;
2012-10-23 17:48:50 +08:00
menu - > setPosition ( ccp ( backSize . width / 2 , backSize . height / 2 ) ) ;
2012-04-19 14:35:52 +08:00
back - > addChild ( menu ) ;
2012-06-14 15:13:16 +08:00
CCActionInterval * rot = CCRotateBy : : create ( 5 , 360 ) ;
CCAction * fe = CCRepeatForever : : create ( rot ) ;
2012-04-19 14:35:52 +08:00
item - > runAction ( fe ) ;
2012-10-23 17:48:50 +08:00
CCActionInterval * move = CCMoveBy : : create ( 3 , ccp ( 200 , 0 ) ) ;
2012-04-19 14:35:52 +08:00
CCActionInterval * move_back = move - > reverse ( ) ;
2012-12-10 14:12:56 +08:00
CCSequence * seq = CCSequence : : create ( move , move_back , NULL ) ;
CCAction * fe2 = CCRepeatForever : : create ( seq ) ;
2012-04-19 14:35:52 +08:00
back - > runAction ( fe2 ) ;
2012-03-21 13:36:24 +08:00
}
std : : string NodeToWorld : : title ( )
{
2012-04-19 14:35:52 +08:00
return " nodeToParent transform " ;
2012-03-21 13:36:24 +08:00
}
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// CameraOrbitTest
//
//------------------------------------------------------------------
2012-03-21 13:36:24 +08:00
void CameraOrbitTest : : onEnter ( )
{
2012-04-19 14:35:52 +08:00
TestCocosNodeDemo : : onEnter ( ) ;
CCDirector : : sharedDirector ( ) - > setProjection ( kCCDirectorProjection3D ) ;
2012-03-21 13:36:24 +08:00
}
void CameraOrbitTest : : onExit ( )
{
2012-04-19 14:35:52 +08:00
CCDirector : : sharedDirector ( ) - > setProjection ( kCCDirectorProjection2D ) ;
TestCocosNodeDemo : : onExit ( ) ;
2012-03-21 13:36:24 +08:00
}
CameraOrbitTest : : CameraOrbitTest ( )
{
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-03-21 13:36:24 +08:00
2012-06-14 15:13:16 +08:00
CCSprite * p = CCSprite : : create ( s_back3 ) ;
2012-04-19 14:35:52 +08:00
addChild ( p , 0 ) ;
2012-10-23 17:48:50 +08:00
p - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
2012-04-19 14:35:52 +08:00
p - > setOpacity ( 128 ) ;
CCSprite * sprite ;
CCOrbitCamera * orbit ;
CCSize ss ;
// LEFT
2012-03-21 13:36:24 +08:00
s = p - > getContentSize ( ) ;
2012-06-14 15:13:16 +08:00
sprite = CCSprite : : create ( s_pPathGrossini ) ;
2012-04-19 14:35:52 +08:00
sprite - > setScale ( 0.5f ) ;
p - > addChild ( sprite , 0 ) ;
2012-10-23 17:48:50 +08:00
sprite - > setPosition ( ccp ( s . width / 4 * 1 , s . height / 2 ) ) ;
2012-06-14 15:13:16 +08:00
orbit = CCOrbitCamera : : create ( 2 , 1 , 0 , 0 , 360 , 0 , 0 ) ;
sprite - > runAction ( CCRepeatForever : : create ( orbit ) ) ;
2012-04-19 14:35:52 +08:00
// CENTER
2012-06-14 15:13:16 +08:00
sprite = CCSprite : : create ( s_pPathGrossini ) ;
2012-04-19 14:35:52 +08:00
sprite - > setScale ( 1.0f ) ;
p - > addChild ( sprite , 0 ) ;
2012-10-23 17:48:50 +08:00
sprite - > setPosition ( ccp ( s . width / 4 * 2 , s . height / 2 ) ) ;
2012-06-14 15:13:16 +08:00
orbit = CCOrbitCamera : : create ( 2 , 1 , 0 , 0 , 360 , 45 , 0 ) ;
sprite - > runAction ( CCRepeatForever : : create ( orbit ) ) ;
2012-04-19 14:35:52 +08:00
// RIGHT
2012-06-14 15:13:16 +08:00
sprite = CCSprite : : create ( s_pPathGrossini ) ;
2012-04-19 14:35:52 +08:00
sprite - > setScale ( 2.0f ) ;
p - > addChild ( sprite , 0 ) ;
2012-10-23 17:48:50 +08:00
sprite - > setPosition ( ccp ( s . width / 4 * 3 , s . height / 2 ) ) ;
2012-04-19 14:35:52 +08:00
ss = sprite - > getContentSize ( ) ;
2012-06-14 15:13:16 +08:00
orbit = CCOrbitCamera : : create ( 2 , 1 , 0 , 0 , 360 , 90 , - 45 ) ,
sprite - > runAction ( CCRepeatForever : : create ( orbit ) ) ;
2012-04-19 14:35:52 +08:00
// PARENT
2012-06-14 15:13:16 +08:00
orbit = CCOrbitCamera : : create ( 10 , 1 , 0 , 0 , 360 , 0 , 90 ) ;
p - > runAction ( CCRepeatForever : : create ( orbit ) ) ;
2012-04-19 14:35:52 +08:00
setScale ( 1 ) ;
2012-03-21 13:36:24 +08:00
}
std : : string CameraOrbitTest : : title ( )
{
2012-04-19 14:35:52 +08:00
return " Camera Orbit test " ;
2012-03-21 13:36:24 +08:00
}
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// CameraZoomTest
//
//------------------------------------------------------------------
2012-03-21 13:36:24 +08:00
void CameraZoomTest : : onEnter ( )
{
2012-04-19 14:35:52 +08:00
TestCocosNodeDemo : : onEnter ( ) ;
CCDirector : : sharedDirector ( ) - > setProjection ( kCCDirectorProjection3D ) ;
2012-03-21 13:36:24 +08:00
}
void CameraZoomTest : : onExit ( )
{
2012-04-19 14:35:52 +08:00
CCDirector : : sharedDirector ( ) - > setProjection ( kCCDirectorProjection2D ) ;
TestCocosNodeDemo : : onExit ( ) ;
2012-03-21 13:36:24 +08:00
}
CameraZoomTest : : CameraZoomTest ( )
{
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
CCSprite * sprite ;
CCCamera * cam ;
// LEFT
2012-06-14 15:13:16 +08:00
sprite = CCSprite : : create ( s_pPathGrossini ) ;
2012-04-19 14:35:52 +08:00
addChild ( sprite , 0 ) ;
2012-10-23 17:48:50 +08:00
sprite - > setPosition ( ccp ( s . width / 4 * 1 , s . height / 2 ) ) ;
2012-04-19 14:35:52 +08:00
cam = sprite - > getCamera ( ) ;
cam - > setEyeXYZ ( 0 , 0 , 415 / 2 ) ;
cam - > setCenterXYZ ( 0 , 0 , 0 ) ;
// CENTER
2012-06-14 15:13:16 +08:00
sprite = CCSprite : : create ( s_pPathGrossini ) ;
2012-04-19 14:35:52 +08:00
addChild ( sprite , 0 , 40 ) ;
2012-10-23 17:48:50 +08:00
sprite - > setPosition ( ccp ( s . width / 4 * 2 , s . height / 2 ) ) ;
2012-04-19 14:35:52 +08:00
// RIGHT
2012-06-14 15:13:16 +08:00
sprite = CCSprite : : create ( s_pPathGrossini ) ;
2012-04-19 14:35:52 +08:00
addChild ( sprite , 0 , 20 ) ;
2012-10-23 17:48:50 +08:00
sprite - > setPosition ( ccp ( s . width / 4 * 3 , s . height / 2 ) ) ;
2012-04-19 14:35:52 +08:00
2013-06-15 14:03:30 +08:00
_z = 0 ;
2012-04-19 14:35:52 +08:00
scheduleUpdate ( ) ;
2012-03-21 13:36:24 +08:00
}
2012-06-08 13:55:28 +08:00
void CameraZoomTest : : update ( float dt )
2012-03-21 13:36:24 +08:00
{
2012-04-19 14:35:52 +08:00
CCNode * sprite ;
CCCamera * cam ;
2013-06-15 14:03:30 +08:00
_z + = dt * 100 ;
2012-04-19 14:35:52 +08:00
sprite = getChildByTag ( 20 ) ;
cam = sprite - > getCamera ( ) ;
2013-06-15 14:03:30 +08:00
cam - > setEyeXYZ ( 0 , 0 , _z ) ;
2012-04-19 14:35:52 +08:00
sprite = getChildByTag ( 40 ) ;
cam = sprite - > getCamera ( ) ;
2013-06-15 14:03:30 +08:00
cam - > setEyeXYZ ( 0 , 0 , - _z ) ;
2012-03-21 13:36:24 +08:00
}
std : : string CameraZoomTest : : title ( )
{
2012-04-19 14:35:52 +08:00
return " Camera Zoom test " ;
2012-03-21 13:36:24 +08:00
}
2010-08-26 15:09:02 +08:00
//------------------------------------------------------------------
//
// CameraCenterTest
//
//------------------------------------------------------------------
2012-03-21 13:36:24 +08:00
CameraCenterTest : : CameraCenterTest ( )
{
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
CCSprite * sprite ;
CCOrbitCamera * orbit ;
// LEFT-TOP
2012-06-14 15:13:16 +08:00
sprite = CCSprite : : create ( " Images/white-512x512.png " ) ;
2012-04-19 14:35:52 +08:00
addChild ( sprite , 0 ) ;
2012-10-23 17:48:50 +08:00
sprite - > setPosition ( ccp ( s . width / 5 * 1 , s . height / 5 * 1 ) ) ;
2012-04-19 14:35:52 +08:00
sprite - > setColor ( ccRED ) ;
sprite - > setTextureRect ( CCRectMake ( 0 , 0 , 120 , 50 ) ) ;
2012-06-14 15:13:16 +08:00
orbit = CCOrbitCamera : : create ( 10 , 1 , 0 , 0 , 360 , 0 , 0 ) ;
sprite - > runAction ( CCRepeatForever : : create ( orbit ) ) ;
2012-10-23 17:48:50 +08:00
// [sprite setAnchorPoint: ccp(0,1));
2012-04-19 14:35:52 +08:00
// LEFT-BOTTOM
2012-06-14 15:13:16 +08:00
sprite = CCSprite : : create ( " Images/white-512x512.png " ) ;
2012-04-19 14:35:52 +08:00
addChild ( sprite , 0 , 40 ) ;
2012-10-23 17:48:50 +08:00
sprite - > setPosition ( ccp ( s . width / 5 * 1 , s . height / 5 * 4 ) ) ;
2012-04-19 14:35:52 +08:00
sprite - > setColor ( ccBLUE ) ;
sprite - > setTextureRect ( CCRectMake ( 0 , 0 , 120 , 50 ) ) ;
2012-06-14 15:13:16 +08:00
orbit = CCOrbitCamera : : create ( 10 , 1 , 0 , 0 , 360 , 0 , 0 ) ;
sprite - > runAction ( CCRepeatForever : : create ( orbit ) ) ;
2012-04-19 14:35:52 +08:00
// RIGHT-TOP
2012-06-14 15:13:16 +08:00
sprite = CCSprite : : create ( " Images/white-512x512.png " ) ;
2012-04-19 14:35:52 +08:00
addChild ( sprite , 0 ) ;
2012-10-23 17:48:50 +08:00
sprite - > setPosition ( ccp ( s . width / 5 * 4 , s . height / 5 * 1 ) ) ;
2012-04-19 14:35:52 +08:00
sprite - > setColor ( ccYELLOW ) ;
sprite - > setTextureRect ( CCRectMake ( 0 , 0 , 120 , 50 ) ) ;
2012-06-14 15:13:16 +08:00
orbit = CCOrbitCamera : : create ( 10 , 1 , 0 , 0 , 360 , 0 , 0 ) ;
sprite - > runAction ( CCRepeatForever : : create ( orbit ) ) ;
2012-04-19 14:35:52 +08:00
// RIGHT-BOTTOM
2012-06-14 15:13:16 +08:00
sprite = CCSprite : : create ( " Images/white-512x512.png " ) ;
2012-04-19 14:35:52 +08:00
addChild ( sprite , 0 , 40 ) ;
2012-10-23 17:48:50 +08:00
sprite - > setPosition ( ccp ( s . width / 5 * 4 , s . height / 5 * 4 ) ) ;
2012-04-19 14:35:52 +08:00
sprite - > setColor ( ccGREEN ) ;
sprite - > setTextureRect ( CCRectMake ( 0 , 0 , 120 , 50 ) ) ;
2012-06-14 15:13:16 +08:00
orbit = CCOrbitCamera : : create ( 10 , 1 , 0 , 0 , 360 , 0 , 0 ) ;
sprite - > runAction ( CCRepeatForever : : create ( orbit ) ) ;
2012-04-19 14:35:52 +08:00
// CENTER
2012-06-14 15:13:16 +08:00
sprite = CCSprite : : create ( " Images/white-512x512.png " ) ;
2012-04-19 14:35:52 +08:00
addChild ( sprite , 0 , 40 ) ;
2012-10-23 17:48:50 +08:00
sprite - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
2012-04-19 14:35:52 +08:00
sprite - > setColor ( ccWHITE ) ;
sprite - > setTextureRect ( CCRectMake ( 0 , 0 , 120 , 50 ) ) ;
2012-06-14 15:13:16 +08:00
orbit = CCOrbitCamera : : create ( 10 , 1 , 0 , 0 , 360 , 0 , 0 ) ;
sprite - > runAction ( CCRepeatForever : : create ( orbit ) ) ;
2012-03-21 13:36:24 +08:00
}
std : : string CameraCenterTest : : title ( )
{
2012-04-19 14:35:52 +08:00
return " Camera Center test " ;
2012-03-21 13:36:24 +08:00
}
std : : string CameraCenterTest : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " Sprites should rotate at the same speed " ;
2012-03-21 13:36:24 +08:00
}
2011-02-23 16:47:25 +08:00
//------------------------------------------------------------------
//
// ConvertToNode
//
2012-03-21 13:36:24 +08:00
//------------------------------------------------------------------
ConvertToNode : : ConvertToNode ( )
{
2012-06-15 15:10:40 +08:00
setTouchEnabled ( true ) ;
2012-03-21 13:36:24 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-06-14 15:13:16 +08:00
CCRotateBy * rotate = CCRotateBy : : create ( 10 , 360 ) ;
CCRepeatForever * action = CCRepeatForever : : create ( rotate ) ;
2012-03-21 13:36:24 +08:00
for ( int i = 0 ; i < 3 ; i + + )
{
2012-06-14 15:13:16 +08:00
CCSprite * sprite = CCSprite : : create ( " Images/grossini.png " ) ;
2012-03-21 13:36:24 +08:00
sprite - > setPosition ( ccp ( s . width / 4 * ( i + 1 ) , s . height / 2 ) ) ;
2012-06-14 15:13:16 +08:00
CCSprite * point = CCSprite : : create ( " Images/r1.png " ) ;
2012-03-21 13:36:24 +08:00
point - > setScale ( 0.25f ) ;
point - > setPosition ( sprite - > getPosition ( ) ) ;
addChild ( point , 10 , 100 + i ) ;
switch ( i )
{
case 0 :
sprite - > setAnchorPoint ( CCPointZero ) ;
break ;
case 1 :
sprite - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
break ;
case 2 :
sprite - > setAnchorPoint ( ccp ( 1 , 1 ) ) ;
break ;
}
point - > setPosition ( sprite - > getPosition ( ) ) ;
CCRepeatForever * copy = ( CCRepeatForever * ) action - > copy ( ) ;
copy - > autorelease ( ) ;
sprite - > runAction ( copy ) ;
addChild ( sprite , i ) ;
}
}
void ConvertToNode : : ccTouchesEnded ( CCSet * touches , CCEvent * event )
{
for ( CCSetIterator it = touches - > begin ( ) ; it ! = touches - > end ( ) ; + + it )
{
CCTouch * touch = ( CCTouch * ) ( * it ) ;
2012-07-31 17:41:53 +08:00
CCPoint location = touch - > getLocation ( ) ;
2012-03-21 13:36:24 +08:00
for ( int i = 0 ; i < 3 ; i + + )
{
CCNode * node = getChildByTag ( 100 + i ) ;
CCPoint p1 , p2 ;
p1 = node - > convertToNodeSpaceAR ( 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 ) ;
}
2012-04-19 14:35:52 +08:00
}
2012-03-21 13:36:24 +08:00
}
std : : string ConvertToNode : : title ( )
{
return " Convert To Node Space " ;
}
std : : string ConvertToNode : : subtitle ( )
{
return " testing convertToNodeSpace / AR. Touch and see console " ;
}
/// NodeOpaqueTest
NodeOpaqueTest : : NodeOpaqueTest ( )
{
2012-04-19 14:35:52 +08:00
CCSprite * background = NULL ;
2012-03-21 13:36:24 +08:00
2012-04-19 14:35:52 +08:00
for ( int i = 0 ; i < 50 ; i + + )
{
2012-06-14 15:13:16 +08:00
background = CCSprite : : create ( " Images/background1.png " ) ;
2012-11-16 17:08:34 +08:00
ccBlendFunc blendFunc = { GL_ONE , GL_ONE_MINUS_SRC_ALPHA } ;
background - > setBlendFunc ( blendFunc ) ;
2012-04-19 14:35:52 +08:00
background - > setAnchorPoint ( CCPointZero ) ;
addChild ( background ) ;
}
2012-03-21 13:36:24 +08:00
}
std : : string NodeOpaqueTest : : title ( )
{
2012-04-19 14:35:52 +08:00
return " Node Opaque Test " ;
2012-03-21 13:36:24 +08:00
}
std : : string NodeOpaqueTest : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " Node rendered with GL_BLEND disabled " ;
2012-03-21 13:36:24 +08:00
}
/// NodeNonOpaqueTest
NodeNonOpaqueTest : : NodeNonOpaqueTest ( )
{
2012-04-19 14:35:52 +08:00
CCSprite * background = NULL ;
2012-03-21 13:36:24 +08:00
2012-04-19 14:35:52 +08:00
for ( int i = 0 ; i < 50 ; i + + )
{
2012-06-14 15:13:16 +08:00
background = CCSprite : : create ( " Images/background1.jpg " ) ;
2012-11-15 18:34:23 +08:00
background - > setBlendFunc ( kCCBlendFuncDisable ) ;
2012-04-19 14:35:52 +08:00
background - > setAnchorPoint ( CCPointZero ) ;
addChild ( background ) ;
}
2012-03-21 13:36:24 +08:00
}
std : : string NodeNonOpaqueTest : : title ( )
{
2012-04-19 14:35:52 +08:00
return " Node Non Opaque Test " ;
2012-03-21 13:36:24 +08:00
}
std : : string NodeNonOpaqueTest : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " Node rendered with GL_BLEND enabled " ;
2012-03-21 13:36:24 +08:00
}
void CocosNodeTestScene : : runThisTest ( )
{
CCLayer * pLayer = nextCocosNodeAction ( ) ;
addChild ( pLayer ) ;
CCDirector : : sharedDirector ( ) - > replaceScene ( this ) ;
}