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()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont* item1 = CCMenuItemFont::create( "Test pushScene", this, menu_selector(SceneTestLayer1::onPushScene) );
|
|
|
|
CCMenuItemFont* item2 = CCMenuItemFont::create( "Test pushScene w/transition", this, menu_selector(SceneTestLayer1::onPushSceneTran) );
|
|
|
|
CCMenuItemFont* item3 = CCMenuItemFont::create( "Quit", this, menu_selector(SceneTestLayer1::onQuit) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu* menu = CCMenu::create( item1, item2, item3, NULL );
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsVertically();
|
|
|
|
|
|
|
|
addChild( menu );
|
|
|
|
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2012-06-14 15:13:16 +08:00
|
|
|
CCSprite* sprite = CCSprite::create(s_pPathGrossini);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sprite);
|
|
|
|
sprite->setPosition( CCPointMake(s.width-40, s.height/2) );
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* rotate = CCRotateBy::create(2, 360);
|
|
|
|
CCAction* repeat = CCRepeatForever::create(rotate);
|
2012-04-19 14:35:52 +08:00
|
|
|
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
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//UXLOG("SceneTestLayer1:testDealloc");
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
2011-02-23 16:47:25 +08:00
|
|
|
void SceneTestLayer1::onEnter()
|
|
|
|
{
|
|
|
|
CCLOG("SceneTestLayer1#onEnter");
|
|
|
|
CCLayer::onEnter();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTestLayer1::onEnterTransitionDidFinish()
|
|
|
|
{
|
|
|
|
CCLOG("SceneTestLayer1#onEnterTransitionDidFinish");
|
|
|
|
CCLayer::onEnterTransitionDidFinish();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void SceneTestLayer1::onPushScene(CCObject* pSender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCScene* scene = new SceneTestScene();
|
2010-09-01 11:34:30 +08:00
|
|
|
CCLayer* pLayer = new SceneTestLayer2();
|
|
|
|
scene->addChild( pLayer, 0 );
|
2012-04-19 14:35:52 +08:00
|
|
|
CCDirector::sharedDirector()->pushScene( scene );
|
2010-09-13 18:04:36 +08:00
|
|
|
scene->release();
|
|
|
|
pLayer->release();
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void SceneTestLayer1::onPushSceneTran(CCObject* pSender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCScene* scene = new SceneTestScene();
|
2010-09-01 11:34:30 +08:00
|
|
|
CCLayer* pLayer = new SceneTestLayer2();
|
|
|
|
scene->addChild( pLayer, 0 );
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCDirector::sharedDirector()->pushScene( CCTransitionSlideInT::create(1, scene) );
|
2010-09-13 18:04:36 +08:00
|
|
|
scene->release();
|
|
|
|
pLayer->release();
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void SceneTestLayer1::onQuit(CCObject* pSender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//getCocosApp()->exit();
|
|
|
|
//CCDirector::sharedDirector()->popScene();
|
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()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
m_timeCounter = 0;
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont* item1 = CCMenuItemFont::create( "replaceScene", this, menu_selector(SceneTestLayer2::onReplaceScene) );
|
|
|
|
CCMenuItemFont* item2 = CCMenuItemFont::create( "replaceScene w/transition", this, menu_selector(SceneTestLayer2::onReplaceSceneTran) );
|
|
|
|
CCMenuItemFont* item3 = CCMenuItemFont::create( "Go Back", this, menu_selector(SceneTestLayer2::onGoBack) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu* menu = CCMenu::create( item1, item2, item3, NULL );
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsVertically();
|
|
|
|
|
|
|
|
addChild( menu );
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2012-06-14 15:13:16 +08:00
|
|
|
CCSprite* sprite = CCSprite::create(s_pPathGrossini);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sprite);
|
|
|
|
sprite->setPosition( CCPointMake(s.width-40, s.height/2) );
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* rotate = CCRotateBy::create(2, 360);
|
|
|
|
CCAction* repeat = CCRepeatForever::create(rotate);
|
2012-04-19 14:35:52 +08:00
|
|
|
sprite->runAction(repeat);
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2012-04-19 14:35:52 +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
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//m_timeCounter += dt;
|
|
|
|
//if( m_timeCounter > 10 )
|
|
|
|
// onReplaceScene(this);
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void SceneTestLayer2::onGoBack(CCObject* pSender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCDirector::sharedDirector()->popScene();
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void SceneTestLayer2::onReplaceScene(CCObject* pSender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCScene* pScene = new SceneTestScene();
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLayer* pLayer = SceneTestLayer3::create();
|
2010-09-01 11:34:30 +08:00
|
|
|
pScene->addChild( pLayer, 0 );
|
2012-04-19 14:35:52 +08:00
|
|
|
CCDirector::sharedDirector()->replaceScene( pScene );
|
2010-09-13 18:04:36 +08:00
|
|
|
pScene->release();
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
void SceneTestLayer2::onReplaceSceneTran(CCObject* pSender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCScene* pScene = new SceneTestScene();
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLayer* pLayer = SceneTestLayer3::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
pScene->addChild( pLayer, 0 );
|
2012-06-14 15:13:16 +08:00
|
|
|
CCDirector::sharedDirector()->replaceScene( CCTransitionFlipX::create(2, pScene) );
|
2010-09-13 18:04:36 +08:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
|
2012-06-12 16:22:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SceneTestLayer3::init()
|
|
|
|
{
|
|
|
|
if (CCLayerColor::initWithColor(ccc4(0,0,255,255)))
|
|
|
|
{
|
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemFont *item0 = CCMenuItemFont::create("Touch to pushScene (self)", this, menu_selector(SceneTestLayer3::item0Clicked));
|
|
|
|
CCMenuItemFont *item1 = CCMenuItemFont::create("Touch to popScene", this, menu_selector(SceneTestLayer3::item1Clicked));
|
|
|
|
CCMenuItemFont *item2 = CCMenuItemFont::create("Touch to popToRootScene", this, menu_selector(SceneTestLayer3::item2Clicked));
|
2012-06-12 16:22:25 +08:00
|
|
|
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu *menu = CCMenu::create(item0, item1, item2, NULL);
|
2012-06-12 16:22:25 +08:00
|
|
|
this->addChild(menu);
|
|
|
|
menu->alignItemsVertically();
|
|
|
|
|
|
|
|
this->schedule(schedule_selector(SceneTestLayer3::testDealloc));
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCSprite* sprite = CCSprite::create(s_pPathGrossini);
|
2012-06-12 16:22:25 +08:00
|
|
|
addChild(sprite);
|
|
|
|
sprite->setPosition( CCPointMake(s.width/2, 40) );
|
2012-06-14 15:13:16 +08:00
|
|
|
CCActionInterval* rotate = CCRotateBy::create(2, 360);
|
|
|
|
CCAction* repeat = CCRepeatForever::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
|
|
|
{
|
2012-06-12 16:22:25 +08:00
|
|
|
CCLog("Layer3:testDealloc");
|
|
|
|
}
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2012-06-12 16:22:25 +08:00
|
|
|
void SceneTestLayer3::item0Clicked(CCObject* pSender)
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScene *newScene = CCScene::create();
|
|
|
|
newScene->addChild(SceneTestLayer3::create());
|
|
|
|
CCDirector::sharedDirector()->pushScene(CCTransitionFade::create(0.5, newScene, ccc3(0,255,255)));
|
2010-12-17 23:44:19 +08:00
|
|
|
}
|
|
|
|
|
2012-06-12 16:22:25 +08:00
|
|
|
void SceneTestLayer3::item1Clicked(CCObject* pSender)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCDirector::sharedDirector()->popScene();
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
2012-06-12 16:22:25 +08:00
|
|
|
void SceneTestLayer3::item2Clicked(CCObject* pSender)
|
|
|
|
{
|
|
|
|
CCDirector::sharedDirector()->popToRootScene();
|
|
|
|
}
|
|
|
|
|
2010-09-01 11:34:30 +08:00
|
|
|
void SceneTestScene::runThisTest()
|
|
|
|
{
|
|
|
|
CCLayer* pLayer = new SceneTestLayer1();
|
|
|
|
addChild(pLayer);
|
2010-09-13 18:04:36 +08:00
|
|
|
pLayer->release();
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2010-11-11 11:18:58 +08:00
|
|
|
CCDirector::sharedDirector()->replaceScene(this);
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|