2013-02-19 15:38:30 +08:00
|
|
|
#include "HelloWorldScene.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
|
2013-09-19 07:50:26 +08:00
|
|
|
Scene* HelloWorld::createScene()
|
2013-02-19 15:38:30 +08:00
|
|
|
{
|
|
|
|
// 'scene' is an autorelease object
|
2013-09-19 07:50:26 +08:00
|
|
|
auto scene = Scene::create();
|
2013-02-19 15:38:30 +08:00
|
|
|
|
|
|
|
// 'layer' is an autorelease object
|
2013-09-19 07:50:26 +08:00
|
|
|
auto layer = HelloWorld::create();
|
2013-02-19 15:38:30 +08:00
|
|
|
|
|
|
|
// add layer as a child to scene
|
|
|
|
scene->addChild(layer);
|
|
|
|
|
|
|
|
// return the scene
|
|
|
|
return scene;
|
|
|
|
}
|
|
|
|
|
|
|
|
// on "init" you need to initialize your instance
|
|
|
|
bool HelloWorld::init()
|
|
|
|
{
|
|
|
|
//////////////////////////////
|
|
|
|
// 1. super init first
|
2013-06-20 22:18:43 +08:00
|
|
|
if ( !Layer::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
|
|
|
|
2014-05-16 22:21:36 +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
|
|
|
{
|
2013-07-12 11:50:36 +08:00
|
|
|
Director::getInstance()->end();
|
2013-02-19 15:38:30 +08:00
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
|
|
exit(0);
|
|
|
|
#endif
|
|
|
|
}
|