2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-12-17 23:44:19 +08:00
|
|
|
#include "SceneTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2015-04-09 08:37:30 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
SceneTests::SceneTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(SceneTestScene);
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
auto item1 = MenuItemFont::create("Test pushScene", AX_CALLBACK_1(SceneTestLayer1::onPushScene, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
auto item2 =
|
2022-07-15 19:17:01 +08:00
|
|
|
MenuItemFont::create("Test pushScene w/transition", AX_CALLBACK_1(SceneTestLayer1::onPushSceneTran, this));
|
|
|
|
auto item3 = MenuItemFont::create("Quit", AX_CALLBACK_1(SceneTestLayer1::onQuit, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto menu = Menu::create(item1, item2, item3, nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsVertically();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
addChild(menu);
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create(s_pathGrossini);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sprite);
|
2021-12-28 16:06:23 +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);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_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
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
// AXLOG("SceneTestLayer1:testDealloc");
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|
|
|
|
|
2011-02-23 16:47:25 +08:00
|
|
|
void SceneTestLayer1::onEnter()
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("SceneTestLayer1#onEnter");
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2011-02-23 16:47:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTestLayer1::onEnterTransitionDidFinish()
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("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()
|
|
|
|
{
|
2021-12-28 16:06:23 +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
|
|
|
{
|
2015-04-09 15:43:01 +08:00
|
|
|
auto scene = SceneTestScene::create(2);
|
2021-12-28 16:06:23 +08:00
|
|
|
Director::getInstance()->pushScene(scene);
|
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
|
|
|
{
|
2015-04-09 15:43:01 +08:00
|
|
|
auto scene = SceneTestScene::create(2);
|
2021-12-28 16:06:23 +08:00
|
|
|
Director::getInstance()->pushScene(TransitionSlideInT::create(1, scene));
|
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
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// getCocosApp()->exit();
|
|
|
|
// Director::getInstance()->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
|
2021-12-28 16:06:23 +08:00
|
|
|
// 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
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
auto item1 = MenuItemFont::create("replaceScene", AX_CALLBACK_1(SceneTestLayer2::onReplaceScene, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
auto item2 =
|
2022-07-15 19:17:01 +08:00
|
|
|
MenuItemFont::create("replaceScene w/transition", AX_CALLBACK_1(SceneTestLayer2::onReplaceSceneTran, this));
|
|
|
|
auto item3 = MenuItemFont::create("Go Back", AX_CALLBACK_1(SceneTestLayer2::onGoBack, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto menu = Menu::create(item1, item2, item3, nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->alignItemsVertically();
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
addChild(menu);
|
|
|
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create(s_pathGrossini);
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(sprite);
|
2021-12-28 16:06:23 +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
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_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;
|
2021-12-28 16:06:23 +08:00
|
|
|
// 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
|
|
|
{
|
2015-04-09 15:43:01 +08:00
|
|
|
auto scene = SceneTestScene::create(3);
|
2021-12-28 16:06:23 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
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
|
|
|
{
|
2015-04-09 15:43:01 +08:00
|
|
|
auto scene = SceneTestScene::create(3);
|
2021-12-28 16:06:23 +08:00
|
|
|
Director::getInstance()->replaceScene(TransitionFlipX::create(2, scene));
|
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
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
SceneTestLayer3::SceneTestLayer3() {}
|
2012-06-12 16:22:25 +08:00
|
|
|
|
|
|
|
bool SceneTestLayer3::init()
|
|
|
|
{
|
2021-12-28 16:06:23 +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
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto item0 =
|
2022-07-15 19:17:01 +08:00
|
|
|
MenuItemFont::create("Touch to pushScene (self)", AX_CALLBACK_1(SceneTestLayer3::item0Clicked, this));
|
|
|
|
auto item1 = MenuItemFont::create("Touch to popScene", AX_CALLBACK_1(SceneTestLayer3::item1Clicked, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
auto item2 =
|
2022-07-15 19:17:01 +08:00
|
|
|
MenuItemFont::create("Touch to popToRootScene", AX_CALLBACK_1(SceneTestLayer3::item2Clicked, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
auto item3 = MenuItemFont::create("Touch to popToSceneStackLevel(2)",
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_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();
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
this->schedule(AX_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);
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite->setPosition(Vec2(s.width / 2, 40.0f));
|
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
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-05-31 07:42:05 +08:00
|
|
|
auto newScene = Scene::createWithSize(s);
|
2013-06-08 08:21:11 +08:00
|
|
|
newScene->addChild(SceneTestLayer3::create());
|
2021-12-28 16:06: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
|
|
|
}
|
|
|
|
|
2015-04-09 15:43:01 +08:00
|
|
|
SceneTestScene* SceneTestScene::create(int testIndex /* = 1 */)
|
2010-09-01 11:34:30 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
auto scene = new SceneTestScene;
|
|
|
|
if (scene->init())
|
2015-04-03 14:31:03 +08:00
|
|
|
{
|
2015-04-09 15:43:01 +08:00
|
|
|
scene->autorelease();
|
|
|
|
switch (testIndex)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
scene->addChild(SceneTestLayer1::create());
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
scene->addChild(SceneTestLayer2::create());
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
scene->addChild(SceneTestLayer3::create());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete scene;
|
|
|
|
scene = nullptr;
|
2015-04-03 14:31:03 +08:00
|
|
|
}
|
2010-09-01 11:34:30 +08:00
|
|
|
|
2015-04-09 15:43:01 +08:00
|
|
|
return scene;
|
2010-09-01 11:34:30 +08:00
|
|
|
}
|