axmol/samples/Cpp/TestCpp/Classes/SceneTest/SceneTest.cpp

231 lines
6.7 KiB
C++
Raw Normal View History

2010-12-17 23:44:19 +08:00
#include "SceneTest.h"
#include "../testResource.h"
2010-09-01 11:34:30 +08:00
//------------------------------------------------------------------
//
// SceneTestLayer1
//
//------------------------------------------------------------------
2010-12-17 23:44:19 +08:00
enum
{
MID_PUSHSCENE = 100,
MID_PUSHSCENETRAN,
MID_QUIT,
MID_REPLACESCENE,
MID_REPLACESCENETRAN,
MID_GOBACK
2010-12-17 23:44:19 +08:00
};
2010-09-01 11:34:30 +08:00
SceneTestLayer1::SceneTestLayer1()
{
MenuItemFont* item1 = MenuItemFont::create( "Test pushScene", CC_CALLBACK_1(SceneTestLayer1::onPushScene, this));
MenuItemFont* item2 = MenuItemFont::create( "Test pushScene w/transition", CC_CALLBACK_1(SceneTestLayer1::onPushSceneTran, this));
MenuItemFont* item3 = MenuItemFont::create( "Quit", CC_CALLBACK_1(SceneTestLayer1::onQuit, this));
Menu* menu = Menu::create( item1, item2, item3, NULL );
menu->alignItemsVertically();
addChild( menu );
Size s = Director::getInstance()->getWinSize();
Sprite* sprite = Sprite::create(s_pPathGrossini);
addChild(sprite);
2013-07-12 14:11:55 +08:00
sprite->setPosition( Point(s.width-40, s.height/2) );
ActionInterval* rotate = RotateBy::create(2, 360);
Action* repeat = RepeatForever::create(rotate);
sprite->runAction(repeat);
schedule( schedule_selector(SceneTestLayer1::testDealloc) );
2010-09-01 11:34:30 +08:00
}
2012-06-08 13:55:28 +08:00
void SceneTestLayer1::testDealloc(float dt)
2010-09-01 11:34:30 +08:00
{
//CCLOG("SceneTestLayer1:testDealloc");
2010-09-01 11:34:30 +08:00
}
2011-02-23 16:47:25 +08:00
void SceneTestLayer1::onEnter()
{
CCLOG("SceneTestLayer1#onEnter");
Layer::onEnter();
2011-02-23 16:47:25 +08:00
}
void SceneTestLayer1::onEnterTransitionDidFinish()
{
CCLOG("SceneTestLayer1#onEnterTransitionDidFinish");
Layer::onEnterTransitionDidFinish();
2011-02-23 16:47:25 +08:00
}
2010-09-01 11:34:30 +08:00
SceneTestLayer1::~SceneTestLayer1()
{
//NSLog(@"SceneTestLayer1 - dealloc");
2010-09-01 11:34:30 +08:00
}
void SceneTestLayer1::onPushScene(Object* pSender)
2010-09-01 11:34:30 +08:00
{
Scene* scene = new SceneTestScene();
Layer* pLayer = new SceneTestLayer2();
2010-09-01 11:34:30 +08:00
scene->addChild( pLayer, 0 );
Director::getInstance()->pushScene( scene );
scene->release();
pLayer->release();
2010-09-01 11:34:30 +08:00
}
void SceneTestLayer1::onPushSceneTran(Object* pSender)
2010-09-01 11:34:30 +08:00
{
Scene* scene = new SceneTestScene();
Layer* pLayer = new SceneTestLayer2();
2010-09-01 11:34:30 +08:00
scene->addChild( pLayer, 0 );
Director::getInstance()->pushScene( TransitionSlideInT::create(1, scene) );
scene->release();
pLayer->release();
2010-09-01 11:34:30 +08:00
}
void SceneTestLayer1::onQuit(Object* pSender)
2010-09-01 11:34:30 +08:00
{
//getCocosApp()->exit();
//CCDirector::getInstance()->popScene();
2010-09-01 11:34:30 +08:00
//// 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)];
2010-12-17 23:44:19 +08:00
}
2010-09-01 11:34:30 +08:00
//------------------------------------------------------------------
//
// SceneTestLayer2
//
//------------------------------------------------------------------
2010-12-17 23:44:19 +08:00
2010-09-01 11:34:30 +08:00
SceneTestLayer2::SceneTestLayer2()
{
_timeCounter = 0;
2010-09-01 11:34:30 +08:00
MenuItemFont* item1 = MenuItemFont::create( "replaceScene", CC_CALLBACK_1(SceneTestLayer2::onReplaceScene, this));
MenuItemFont* item2 = MenuItemFont::create( "replaceScene w/transition", CC_CALLBACK_1(SceneTestLayer2::onReplaceSceneTran, this));
MenuItemFont* item3 = MenuItemFont::create( "Go Back", CC_CALLBACK_1(SceneTestLayer2::onGoBack, this));
Menu* menu = Menu::create( item1, item2, item3, NULL );
menu->alignItemsVertically();
addChild( menu );
2010-09-01 11:34:30 +08:00
Size s = Director::getInstance()->getWinSize();
Sprite* sprite = Sprite::create(s_pPathGrossini);
addChild(sprite);
2013-07-12 14:11:55 +08:00
sprite->setPosition( Point(s.width-40, s.height/2) );
ActionInterval* rotate = RotateBy::create(2, 360);
Action* repeat = RepeatForever::create(rotate);
sprite->runAction(repeat);
2010-09-01 11:34:30 +08:00
schedule( schedule_selector(SceneTestLayer2::testDealloc) );
2010-09-01 11:34:30 +08:00
}
2012-06-08 13:55:28 +08:00
void SceneTestLayer2::testDealloc(float dt)
2010-09-01 11:34:30 +08:00
{
//_timeCounter += dt;
//if( _timeCounter > 10 )
// onReplaceScene(this);
2010-09-01 11:34:30 +08:00
}
void SceneTestLayer2::onGoBack(Object* pSender)
2010-09-01 11:34:30 +08:00
{
Director::getInstance()->popScene();
2010-09-01 11:34:30 +08:00
}
void SceneTestLayer2::onReplaceScene(Object* pSender)
2010-09-01 11:34:30 +08:00
{
Scene* pScene = new SceneTestScene();
Layer* pLayer = SceneTestLayer3::create();
2010-09-01 11:34:30 +08:00
pScene->addChild( pLayer, 0 );
Director::getInstance()->replaceScene( pScene );
pScene->release();
2010-09-01 11:34:30 +08:00
}
void SceneTestLayer2::onReplaceSceneTran(Object* pSender)
2010-09-01 11:34:30 +08:00
{
Scene* pScene = new SceneTestScene();
Layer* pLayer = SceneTestLayer3::create();
pScene->addChild( pLayer, 0 );
Director::getInstance()->replaceScene( TransitionFlipX::create(2, pScene) );
pScene->release();
2010-12-17 23:44:19 +08:00
}
2010-09-01 11:34:30 +08:00
//------------------------------------------------------------------
//
// SceneTestLayer3
//
//------------------------------------------------------------------
2010-12-17 23:44:19 +08:00
2010-09-01 11:34:30 +08:00
SceneTestLayer3::SceneTestLayer3()
{
}
bool SceneTestLayer3::init()
{
if (LayerColor::initWithColor(Color4B(0,0,255,255)))
{
Size s = Director::getInstance()->getWinSize();
MenuItemFont *item0 = MenuItemFont::create("Touch to pushScene (self)", CC_CALLBACK_1(SceneTestLayer3::item0Clicked, this));
MenuItemFont *item1 = MenuItemFont::create("Touch to popScene", CC_CALLBACK_1(SceneTestLayer3::item1Clicked, this));
MenuItemFont *item2 = MenuItemFont::create("Touch to popToRootScene", CC_CALLBACK_1(SceneTestLayer3::item2Clicked, this));
MenuItemFont *item3 = MenuItemFont::create("Touch to popToSceneStackLevel(2)", CC_CALLBACK_1(SceneTestLayer3::item3Clicked, this));
Menu *menu = Menu::create(item0, item1, item2, item3, NULL);
this->addChild(menu);
menu->alignItemsVertically();
this->schedule(schedule_selector(SceneTestLayer3::testDealloc));
Sprite* sprite = Sprite::create(s_pPathGrossini);
addChild(sprite);
2013-07-12 14:11:55 +08:00
sprite->setPosition( Point(s.width/2, 40) );
ActionInterval* rotate = RotateBy::create(2, 360);
Action* repeat = RepeatForever::create(rotate);
sprite->runAction(repeat);
return true;
}
return false;
2010-09-01 11:34:30 +08:00
}
2012-06-08 13:55:28 +08:00
void SceneTestLayer3::testDealloc(float dt)
2010-09-01 11:34:30 +08:00
{
CCLog("Layer3:testDealloc");
}
2010-09-01 11:34:30 +08:00
void SceneTestLayer3::item0Clicked(Object* pSender)
{
Scene *newScene = Scene::create();
newScene->addChild(SceneTestLayer3::create());
Director::getInstance()->pushScene(TransitionFade::create(0.5, newScene, Color3B(0,255,255)));
2010-12-17 23:44:19 +08:00
}
void SceneTestLayer3::item1Clicked(Object* pSender)
2010-09-01 11:34:30 +08:00
{
Director::getInstance()->popScene();
2010-09-01 11:34:30 +08:00
}
void SceneTestLayer3::item2Clicked(Object* pSender)
{
Director::getInstance()->popToRootScene();
}
void SceneTestLayer3::item3Clicked(Object* pSender)
{
Director::getInstance()->popToSceneStackLevel(2);
}
2010-09-01 11:34:30 +08:00
void SceneTestScene::runThisTest()
{
Layer* pLayer = new SceneTestLayer1();
2010-09-01 11:34:30 +08:00
addChild(pLayer);
pLayer->release();
2010-09-01 11:34:30 +08:00
Director::getInstance()->replaceScene(this);
2010-09-01 11:34:30 +08:00
}