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
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
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()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item1 = MenuItemFont::create( "Test pushScene", CC_CALLBACK_1(SceneTestLayer1::onPushScene, this));
|
|
|
|
auto item2 = MenuItemFont::create( "Test pushScene w/transition", CC_CALLBACK_1(SceneTestLayer1::onPushSceneTran, this));
|
|
|
|
auto item3 = MenuItemFont::create( "Quit", CC_CALLBACK_1(SceneTestLayer1::onQuit, this));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create( item1, item2, item3, nullptr );
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsVertically();
|
|
|
|
|
|
|
|
addChild( menu );
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto sprite = Sprite::create(s_pathGrossini);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sprite);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2(s.width-40, s.height/2) );
|
2013-08-16 16:05:27 +08:00
|
|
|
auto rotate = RotateBy::create(2, 360);
|
|
|
|
auto repeat = RepeatForever::create(rotate);
|
2012-04-19 14:35:52 +08:00
|
|
|
sprite->runAction(repeat);
|
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule( CC_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
|
|
|
{
|
2013-03-03 10:32:09 +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");
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2011-02-23 16:47:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTestLayer1::onEnterTransitionDidFinish()
|
|
|
|
{
|
|
|
|
CCLOG("SceneTestLayer1#onEnterTransitionDidFinish");
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnterTransitionDidFinish();
|
2011-02-23 16:47:25 +08:00
|
|
|
}
|
|
|
|
|
2010-09-01 11:34:30 +08:00
|
|
|
SceneTestLayer1::~SceneTestLayer1()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//NSLog(@"SceneTestLayer1 - dealloc");
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneTestLayer1::onPushScene(Ref* sender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto scene = new (std::nothrow) SceneTestScene();
|
|
|
|
auto layer = new (std::nothrow) SceneTestLayer2();
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->addChild( layer, 0 );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->pushScene( scene );
|
2010-09-13 18:04:36 +08:00
|
|
|
scene->release();
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->release();
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneTestLayer1::onPushSceneTran(Ref* sender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto scene = new (std::nothrow) SceneTestScene();
|
|
|
|
auto layer = new (std::nothrow) SceneTestLayer2();
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->addChild( layer, 0 );
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->pushScene( TransitionSlideInT::create(1, scene) );
|
2010-09-13 18:04:36 +08:00
|
|
|
scene->release();
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->release();
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneTestLayer1::onQuit(Ref* sender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//getCocosApp()->exit();
|
2013-07-23 08:25:44 +08:00
|
|
|
//CCDirector::getInstance()->poscene();
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2012-04-19 14:35:52 +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()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_timeCounter = 0;
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item1 = MenuItemFont::create( "replaceScene", CC_CALLBACK_1(SceneTestLayer2::onReplaceScene, this));
|
|
|
|
auto item2 = MenuItemFont::create( "replaceScene w/transition", CC_CALLBACK_1(SceneTestLayer2::onReplaceSceneTran, this));
|
|
|
|
auto item3 = MenuItemFont::create( "Go Back", CC_CALLBACK_1(SceneTestLayer2::onGoBack, this));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create( item1, item2, item3, nullptr );
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsVertically();
|
|
|
|
|
|
|
|
addChild( menu );
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto sprite = Sprite::create(s_pathGrossini);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sprite);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2(s.width-40, s.height/2) );
|
2013-08-16 16:05:27 +08:00
|
|
|
auto rotate = RotateBy::create(2, 360);
|
|
|
|
auto repeat = RepeatForever::create(rotate);
|
2012-04-19 14:35:52 +08:00
|
|
|
sprite->runAction(repeat);
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
schedule( CC_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
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
//_timeCounter += dt;
|
|
|
|
//if( _timeCounter > 10 )
|
2012-04-19 14:35:52 +08:00
|
|
|
// onReplaceScene(this);
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneTestLayer2::onGoBack(Ref* sender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->popScene();
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneTestLayer2::onReplaceScene(Ref* sender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto scene = new (std::nothrow) SceneTestScene();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = SceneTestLayer3::create();
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->addChild( layer, 0 );
|
|
|
|
Director::getInstance()->replaceScene( scene );
|
|
|
|
scene->release();
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneTestLayer2::onReplaceSceneTran(Ref* sender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto scene = new (std::nothrow) SceneTestScene();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = SceneTestLayer3::create();
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->addChild( layer, 0 );
|
|
|
|
Director::getInstance()->replaceScene( TransitionFlipX::create(2, scene) );
|
|
|
|
scene->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()
|
|
|
|
{
|
|
|
|
|
2012-06-12 16:22:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SceneTestLayer3::init()
|
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
if (LayerColor::initWithColor(Color4B(0,0,255,255)))
|
2012-06-12 16:22:25 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-06-12 16:22:25 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item0 = MenuItemFont::create("Touch to pushScene (self)", CC_CALLBACK_1(SceneTestLayer3::item0Clicked, this));
|
|
|
|
auto item1 = MenuItemFont::create("Touch to poscene", CC_CALLBACK_1(SceneTestLayer3::item1Clicked, this));
|
|
|
|
auto item2 = MenuItemFont::create("Touch to popToRootScene", CC_CALLBACK_1(SceneTestLayer3::item2Clicked, this));
|
|
|
|
auto item3 = MenuItemFont::create("Touch to popToSceneStackLevel(2)", CC_CALLBACK_1(SceneTestLayer3::item3Clicked, this));
|
2013-05-01 06:33:22 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto menu = Menu::create(item0, item1, item2, item3, nullptr);
|
2013-05-01 06:33:22 +08:00
|
|
|
this->addChild(menu);
|
2012-06-12 16:22:25 +08:00
|
|
|
menu->alignItemsVertically();
|
|
|
|
|
2014-10-04 00:38:36 +08:00
|
|
|
this->schedule(CC_SCHEDULE_SELECTOR(SceneTestLayer3::testDealloc));
|
2012-06-12 16:22:25 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create(s_pathGrossini);
|
2012-06-12 16:22:25 +08:00
|
|
|
addChild(sprite);
|
2014-05-15 01:07:09 +08:00
|
|
|
sprite->setPosition( Vec2(s.width/2, 40) );
|
2013-08-16 16:05:27 +08:00
|
|
|
auto rotate = RotateBy::create(2, 360);
|
|
|
|
auto repeat = RepeatForever::create(rotate);
|
2012-06-12 16:22:25 +08:00
|
|
|
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
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Layer3:testDealloc");
|
2012-06-12 16:22:25 +08:00
|
|
|
}
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneTestLayer3::item0Clicked(Ref* sender)
|
2012-06-12 16:22:25 +08:00
|
|
|
{
|
2014-05-31 07:42:05 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
auto newScene = Scene::createWithSize(s);
|
2013-06-08 08:21:11 +08:00
|
|
|
newScene->addChild(SceneTestLayer3::create());
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->pushScene(TransitionFade::create(0.5, newScene, Color3B(0,255,255)));
|
2010-12-17 23:44:19 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneTestLayer3::item1Clicked(Ref* sender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->popScene();
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneTestLayer3::item2Clicked(Ref* sender)
|
2012-06-12 16:22:25 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->popToRootScene();
|
2012-06-12 16:22:25 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneTestLayer3::item3Clicked(Ref* sender)
|
2013-05-01 06:33:22 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->popToSceneStackLevel(2);
|
2013-05-01 06:33:22 +08:00
|
|
|
}
|
|
|
|
|
2010-09-01 11:34:30 +08:00
|
|
|
void SceneTestScene::runThisTest()
|
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
auto layer = new (std::nothrow) SceneTestLayer1();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
|
|
|
layer->release();
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|