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;
|
|
|
|
}
|
|
|
|
|
2013-07-12 11:50:36 +08:00
|
|
|
Size visibleSize = Director::getInstance()->getVisibleSize();
|
|
|
|
Point 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
|
|
|
|
2013-07-28 00:16:16 +08:00
|
|
|
closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
|
|
|
|
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);
|
2013-07-28 00:16:16 +08:00
|
|
|
menu->setPosition(Point::ZERO);
|
|
|
|
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
|
|
|
|
|
2013-09-19 07:50:26 +08:00
|
|
|
auto label = LabelTTF::create("Hello World", "Arial", 24);
|
2013-02-19 15:38:30 +08:00
|
|
|
|
|
|
|
// position the label on the center of the screen
|
2013-07-28 00:16:16 +08:00
|
|
|
label->setPosition(Point(origin.x + visibleSize.width/2,
|
|
|
|
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
|
2013-07-28 00:16:16 +08:00
|
|
|
sprite->setPosition(Point(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
|
|
|
{
|
2014-03-29 02:27:43 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
|
|
MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
}
|