2013-02-19 15:38:30 +08:00
# include "HelloWorldScene.h"
2016-03-28 14:35:59 +08:00
# include "SimpleAudioEngine.h"
2013-02-19 15:38:30 +08:00
USING_NS_CC ;
2013-09-19 07:50:26 +08:00
Scene * HelloWorld : : createScene ( )
2013-02-19 15:38:30 +08:00
{
2016-12-21 13:49:59 +08:00
return HelloWorld : : create ( ) ;
2013-02-19 15:38:30 +08:00
}
// on "init" you need to initialize your instance
bool HelloWorld : : init ( )
{
//////////////////////////////
// 1. super init first
2016-12-21 13:49:59 +08:00
if ( ! Scene : : init ( ) )
2013-02-19 15:38:30 +08:00
{
return false ;
}
2016-03-04 11:21:30 +08:00
auto visibleSize = Director : : getInstance ( ) - > getVisibleSize ( ) ;
2014-05-16 22:21:36 +08:00
Vec2 origin = Director : : getInstance ( ) - > getVisibleOrigin ( ) ;
2013-02-19 15:38:30 +08:00
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// add a "close" icon to exit the progress. it's an autorelease object
2013-09-19 07:50:26 +08:00
auto closeItem = MenuItemImage : : create (
" CloseNormal.png " ,
" CloseSelected.png " ,
CC_CALLBACK_1 ( HelloWorld : : menuCloseCallback , this ) ) ;
2013-02-19 15:38:30 +08:00
2016-03-28 14:35:59 +08:00
closeItem - > setPosition ( Vec2 ( origin . x + visibleSize . width - closeItem - > getContentSize ( ) . width / 2 ,
2013-07-28 00:16:16 +08:00
origin . y + closeItem - > getContentSize ( ) . height / 2 ) ) ;
2013-02-19 15:38:30 +08:00
// create menu, it's an autorelease object
2013-09-19 07:50:26 +08:00
auto menu = Menu : : create ( closeItem , NULL ) ;
2014-05-16 22:21:36 +08:00
menu - > setPosition ( Vec2 : : ZERO ) ;
2013-07-28 00:16:16 +08:00
this - > addChild ( menu , 1 ) ;
2013-02-19 15:38:30 +08:00
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
2014-10-17 17:02:22 +08:00
auto label = Label : : createWithTTF ( " Hello World " , " fonts/Marker Felt.ttf " , 24 ) ;
2013-02-19 15:38:30 +08:00
// position the label on the center of the screen
2014-05-16 22:21:36 +08:00
label - > setPosition ( Vec2 ( origin . x + visibleSize . width / 2 ,
2013-07-28 00:16:16 +08:00
origin . y + visibleSize . height - label - > getContentSize ( ) . height ) ) ;
2013-02-19 15:38:30 +08:00
// add the label as a child to this layer
2013-07-28 00:16:16 +08:00
this - > addChild ( label , 1 ) ;
2013-02-19 15:38:30 +08:00
// add "HelloWorld" splash screen"
2013-09-19 07:50:26 +08:00
auto sprite = Sprite : : create ( " HelloWorld.png " ) ;
2013-02-19 15:38:30 +08:00
// position the sprite on the center of the screen
2014-05-16 22:21:36 +08:00
sprite - > setPosition ( Vec2 ( visibleSize . width / 2 + origin . x , visibleSize . height / 2 + origin . y ) ) ;
2013-02-19 15:38:30 +08:00
// add the sprite as a child to this layer
2013-07-28 00:16:16 +08:00
this - > addChild ( sprite , 0 ) ;
2013-02-19 15:38:30 +08:00
return true ;
}
2014-02-20 11:31:49 +08:00
void HelloWorld : : menuCloseCallback ( Ref * pSender )
2013-02-19 15:38:30 +08:00
{
2016-06-08 10:55:02 +08:00
//Close the cocos2d-x game scene and quit the application
2013-07-12 11:50:36 +08:00
Director : : getInstance ( ) - > end ( ) ;
2013-02-19 15:38:30 +08:00
2016-06-08 10:55:02 +08:00
# if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
2013-02-19 15:38:30 +08:00
exit ( 0 ) ;
# endif
2016-06-08 10:55: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);
2013-02-19 15:38:30 +08:00
}