add SceneTest code
This commit is contained in:
natural-law 2010-09-01 03:34:30 +00:00
parent ff3d907846
commit c0705de149
5 changed files with 251 additions and 0 deletions

View File

@ -513,6 +513,18 @@
>
</File>
</Filter>
<Filter
Name="SceneTest"
>
<File
RelativePath=".\tests\SceneTest\SceneTest.cpp"
>
</File>
<File
RelativePath=".\tests\SceneTest\SceneTest.h"
>
</File>
</Filter>
</Filter>
<File
RelativePath=".\test_uphoneUnicodeScript.h"

View File

@ -0,0 +1,181 @@
#include "SceneTest.h"
#include "../testResource.h"
//------------------------------------------------------------------
//
// SceneTestLayer1
//
//------------------------------------------------------------------
enum
{
MID_PUSHSCENE = 100,
MID_PUSHSCENETRAN,
MID_QUIT,
MID_REPLACESCENE,
MID_REPLACESCENETRAN,
MID_GOBACK
};
SceneTestLayer1::SceneTestLayer1()
{
CCMenuItemFont* item1 = CCMenuItemFont::itemFromString( "Test pushScene", this, menu_selector(SceneTestLayer1::onPushScene) );
CCMenuItemFont* item2 = CCMenuItemFont::itemFromString( "Test pushScene w/transition", this, menu_selector(SceneTestLayer1::onPushSceneTran) );
CCMenuItemFont* item3 = CCMenuItemFont::itemFromString( "Quit", this, menu_selector(SceneTestLayer1::onQuit) );
CCMenu* menu = CCMenu::menuWithItems( item1, item2, item3, NULL );
menu->alignItemsVertically();
addChild( menu );
CGSize s = CCDirector::getSharedDirector()->getWinSize();
CCSprite* sprite = CCSprite::spriteWithFile(s_pPathGrossini);
addChild(sprite);
sprite->setPosition( CGPointMake(s.width-40, s.height/2) );
CCIntervalAction* rotate = CCRotateBy::actionWithDuration(2, 360);
CCAction* repeat = CCRepeatForever::actionWithAction(rotate);
sprite->runAction(repeat);
schedule( schedule_selector(SceneTestLayer1::testDealloc) );
}
void SceneTestLayer1::testDealloc(ccTime dt)
{
//UXLOG("SceneTestLayer1:testDealloc");
}
SceneTestLayer1::~SceneTestLayer1()
{
//NSLog(@"SceneTestLayer1 - dealloc");
}
void SceneTestLayer1::onPushScene(NSObject* pSender)
{
CCScene* scene = new SceneTestScene();
CCLayer* pLayer = new SceneTestLayer2();
scene->addChild( pLayer, 0 );
CCDirector::getSharedDirector()->pushScene( scene );
}
void SceneTestLayer1::onPushSceneTran(NSObject* pSender)
{
CCScene* scene = new SceneTestScene();
CCLayer* pLayer = new SceneTestLayer2();
scene->addChild( pLayer, 0 );
CCDirector::getSharedDirector()->pushScene( CCSlideInTTransition::transitionWithDuration(1, scene) );
}
void SceneTestLayer1::onQuit(NSObject* pSender)
{
//getCocosApp()->exit();
//CCDirector::getSharedDirector()->popScene();
//// HA HA... no more terminate on sdk v3.0
//// http://developer.apple.com/iphone/library/qa/qa2008/qa1561.html
//if( [[UIApplication sharedApplication] respondsToSelector:@selector(terminate)] )
// [[UIApplication sharedApplication] performSelector:@selector(terminate)];
}
//------------------------------------------------------------------
//
// SceneTestLayer2
//
//------------------------------------------------------------------
SceneTestLayer2::SceneTestLayer2()
{
m_timeCounter = 0;
CCMenuItemFont* item1 = CCMenuItemFont::itemFromString( "replaceScene", this, menu_selector(SceneTestLayer2::onReplaceScene) );
CCMenuItemFont* item2 = CCMenuItemFont::itemFromString( "replaceScene w/transition", this, menu_selector(SceneTestLayer2::onReplaceSceneTran) );
CCMenuItemFont* item3 = CCMenuItemFont::itemFromString( "Go Back", this, menu_selector(SceneTestLayer2::onGoBack) );
CCMenu* menu = CCMenu::menuWithItems( item1, item2, item3, NULL );
menu->alignItemsVertically();
addChild( menu );
CGSize s = CCDirector::getSharedDirector()->getWinSize();
CCSprite* sprite = CCSprite::spriteWithFile(s_pPathGrossini);
addChild(sprite);
sprite->setPosition( CGPointMake(s.width-40, s.height/2) );
CCIntervalAction* rotate = CCRotateBy::actionWithDuration(2, 360);
CCAction* repeat = CCRepeatForever::actionWithAction(rotate);
sprite->runAction(repeat);
schedule( schedule_selector(SceneTestLayer2::testDealloc) );
}
void SceneTestLayer2::testDealloc(ccTime dt)
{
//m_timeCounter += dt;
//if( m_timeCounter > 10 )
// onReplaceScene(this);
}
void SceneTestLayer2::onGoBack(NSObject* pSender)
{
CCDirector::getSharedDirector()->popScene();
}
void SceneTestLayer2::onReplaceScene(NSObject* pSender)
{
CCScene* pScene = new SceneTestScene();
CCLayer* pLayer = new SceneTestLayer3();
pScene->addChild( pLayer, 0 );
CCDirector::getSharedDirector()->replaceScene( pScene );
}
void SceneTestLayer2::onReplaceSceneTran(NSObject* pSender)
{
CCScene* pScene = new SceneTestScene();
CCLayer* pLayer = new SceneTestLayer3();
pScene->addChild( pLayer, 0 );
CCDirector::getSharedDirector()->replaceScene( CCFlipXTransition::transitionWithDuration(2, pScene) );
}
//------------------------------------------------------------------
//
// SceneTestLayer3
//
//------------------------------------------------------------------
SceneTestLayer3::SceneTestLayer3()
{
setIsTouchEnabled( true );
CCLabel* label = CCLabel::labelWithString("Touch to popScene", "Marker Felt", 28);
addChild(label);
CGSize s = CCDirector::getSharedDirector()->getWinSize();
label->setPosition( CGPointMake(s.width/2, s.height/2) );
CCSprite* sprite = CCSprite::spriteWithFile(s_pPathGrossini);
addChild(sprite);
sprite->setPosition( CGPointMake(s.width-40, s.height/2) );
CCIntervalAction* rotate = CCRotateBy::actionWithDuration(2, 360);
CCAction* repeat = CCRepeatForever::actionWithAction(rotate);
sprite->runAction(repeat);
//schedule();
}
void SceneTestLayer3::testDealloc(ccTime dt)
{
}
void SceneTestLayer3::ccTouchesEnded(NSSet* touches, UIEvent* event)
{
static int i = 0;
//UXLOG("SceneTestLayer3::ccTouchesEnded(%d)", ++i);
CCDirector::getSharedDirector()->popScene();
}
void SceneTestScene::runThisTest()
{
CCLayer* pLayer = new SceneTestLayer1();
addChild(pLayer);
CCDirector::getSharedDirector()->replaceScene(this);
}

View File

@ -0,0 +1,53 @@
#ifndef _SCENE_TEST_H_
#define _SCENE_TEST_H_
#include "cocos2d.h"
#include "../testBasic.h"
class SceneTestLayer1 : public CCLayer
{
public:
SceneTestLayer1();
~SceneTestLayer1();
void testDealloc(ccTime dt);
void onPushScene(NSObject* pSender);
void onPushSceneTran(NSObject* pSender);
void onQuit(NSObject* pSender);
//CREATE_NODE(SceneTestLayer1);
} ;
class SceneTestLayer2 : public CCLayer
{
float m_timeCounter;
public:
SceneTestLayer2();
void testDealloc(ccTime dt);
void onGoBack(NSObject* pSender);
void onReplaceScene(NSObject* pSender);
void onReplaceSceneTran(NSObject* pSender);
//CREATE_NODE(SceneTestLayer2);
} ;
class SceneTestLayer3 : public CCColorLayer
{
public:
SceneTestLayer3();
virtual void testDealloc(ccTime dt);
virtual void ccTouchesEnded(NSSet* touches, UIEvent* event);
//CREATE_NODE(SceneTestLayer3);
} ;
class SceneTestScene : public TestScene
{
public:
virtual void runThisTest();
};
#endif

View File

@ -45,6 +45,8 @@ static TestScene* CreateTestScene(int nIdx)
pScene = new ActionManagerTestScene(); break;
case TEST_LAYER:
pScene = new LayerTestScene(); break;
case TEST_SCENE:
pScene = new SceneTestScene(); break;
default:
break;
}

View File

@ -16,6 +16,7 @@
#include "MenuTest/MenuTest.h"
#include "ActionManagerTest/ActionManagerTest.h"
#include "LayerTest/LayerTest.h"
#include "SceneTest/SceneTest.h"
enum
{
@ -34,6 +35,7 @@ enum
TEST_MENU,
TEST_ACTION_MANAGER,
TEST_LAYER,
TEST_SCENE,
TESTS_COUNT,
};
@ -53,6 +55,7 @@ const std::string g_aTestNames[TESTS_COUNT] = {
"MenuTest",
"ActionManagerTest",
"LayerTest",
"SceneTest",
};
#endif