2012-04-19 14:35:52 +08:00
|
|
|
|
#include "testBasic.h"
|
|
|
|
|
#include "controller.h"
|
|
|
|
|
|
|
|
|
|
TestScene::TestScene(bool bPortrait)
|
|
|
|
|
{
|
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
|
Scene::init();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestScene::onEnter()
|
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
|
Scene::onEnter();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
//add the menu item for back to main menu
|
|
|
|
|
//#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
|
2013-06-20 14:17:10 +08:00
|
|
|
|
// LabelBMFont* label = LabelBMFont::create("MainMenu", "fonts/arial16.fnt");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
//#else
|
2013-06-20 14:17:10 +08:00
|
|
|
|
LabelTTF* label = LabelTTF::create("MainMenu", "Arial", 20);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
//#endif
|
2013-06-20 14:17:10 +08:00
|
|
|
|
MenuItemLabel* pMenuItem = MenuItemLabel::create(label, [](Object *sender) {
|
2013-06-08 10:25:53 +08:00
|
|
|
|
/*
|
|
|
|
|
****** GCC Compiler issue on Android and Linux (CLANG compiler is ok) ******
|
2013-06-20 14:17:10 +08:00
|
|
|
|
We couldn't use 'Scene::create' directly since gcc will trigger
|
2013-06-08 10:25:53 +08:00
|
|
|
|
an error called "error: 'this' was not captured for this lambda function".
|
2013-06-20 14:17:10 +08:00
|
|
|
|
This is because 'Scene' is the super class of TestScene, if we invoke 'Scene::create'
|
|
|
|
|
directly in this lambda expression, gcc compiler found 'Scene::create' and it think
|
2013-06-08 10:25:53 +08:00
|
|
|
|
that was the member function of 'TestScene' 's super class, but this lambda function doesn't
|
2013-06-20 14:17:10 +08:00
|
|
|
|
capture anything like 'this', so it has no access to invoke 'Scene::create'.
|
2013-06-08 10:25:53 +08:00
|
|
|
|
|
|
|
|
|
Solution (1): Passing 'this' to this lambda function.
|
2013-06-20 14:17:10 +08:00
|
|
|
|
Solution (2): Don't use 'Scene::create' and don't pass 'this' to this lambda function,
|
|
|
|
|
instead, we just need to new the 'Scene' and initialize the Scene.
|
2013-06-08 10:25:53 +08:00
|
|
|
|
|
|
|
|
|
Semantically, I think in this lambda function, we shouldn't capture any varibles
|
|
|
|
|
outside the scope. So I choose the (2) solution. Commented by James Chen.
|
|
|
|
|
*/
|
2013-06-08 08:21:11 +08:00
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
|
// Scene *pScene = Scene::create();
|
|
|
|
|
Scene *pScene = new Scene();
|
2013-06-08 10:25:53 +08:00
|
|
|
|
if (pScene && pScene->init())
|
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
|
Layer* pLayer = new TestController();
|
2013-06-08 10:25:53 +08:00
|
|
|
|
pScene->addChild(pLayer);
|
|
|
|
|
pLayer->release();
|
2013-07-12 06:24:23 +08:00
|
|
|
|
Director::getInstance()->replaceScene(pScene);
|
2013-06-08 10:25:53 +08:00
|
|
|
|
pScene->release();
|
|
|
|
|
}
|
2013-06-08 08:21:11 +08:00
|
|
|
|
});
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
|
Menu* pMenu =Menu::create(pMenuItem, NULL);
|
2012-10-23 17:48:50 +08:00
|
|
|
|
|
2013-07-12 14:47:36 +08:00
|
|
|
|
pMenu->setPosition( Point::ZERO );
|
2013-07-12 14:11:55 +08:00
|
|
|
|
pMenuItem->setPosition( Point( VisibleRect::right().x - 50, VisibleRect::bottom().y + 25) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
addChild(pMenu, 1);
|
|
|
|
|
}
|