axmol/tests/fairygui-tests/Source/DemoScene.cpp

65 lines
1.6 KiB
C++
Raw Normal View History

2020-08-04 13:15:02 +08:00
#include "DemoScene.h"
#include "MenuScene.h"
USING_NS_AX;
2020-08-04 13:15:02 +08:00
bool DemoScene::init()
{
if (!Scene::init())
{
return false;
}
_groot = GRoot::create(this);
_groot->retain();
continueInit();
//add a closebutton to scene
GObject* closeButton = UIPackage::createObject("MainMenu", "CloseButton");
closeButton->setPosition(_groot->getWidth() - closeButton->getWidth() - 10, _groot->getHeight() - closeButton->getHeight() - 10);
closeButton->addRelation(_groot, RelationType::Right_Right);
closeButton->addRelation(_groot, RelationType::Bottom_Bottom);
closeButton->setSortingOrder(100000);
2022-07-16 10:43:05 +08:00
closeButton->addClickListener(AX_CALLBACK_1(DemoScene::onClose, this));
2020-08-04 13:15:02 +08:00
_groot->addChild(closeButton);
return true;
}
void DemoScene::continueInit()
{
}
void DemoScene::onClose(EventContext* context)
{
if (!dynamic_cast<MenuScene*>(this))
{
Director::getInstance()->replaceScene(MenuScene::create());
}
else
{
2023-08-31 18:59:12 +08:00
//Close the cocos2d-x game scene and quit the application
2020-08-04 13:15:02 +08:00
Director::getInstance()->end();
2023-08-31 18:59:12 +08:00
#if (AX_TARGET_PLATFORM == AX_PLATFORM_IOS)
exit(0);
#endif
2020-08-04 13:15:02 +08:00
/*To navigate back to native iOS screen(if present) without quitting the application ,do not use Director::getInstance()->end() and exit(0) as given above,instead trigger a custom event created in RootViewController.mm as below*/
//EventCustom customEndEvent("game_scene_close_event");
//_eventDispatcher->dispatchEvent(&customEndEvent);
}
}
DemoScene::DemoScene() :
_groot(nullptr)
{
}
DemoScene::~DemoScene()
{
2022-07-16 10:43:05 +08:00
AX_SAFE_RELEASE(_groot);
2020-08-04 13:15:02 +08:00
}