2012-04-19 14:35:52 +08:00
|
|
|
#include "HelloWorldScene.h"
|
2012-10-11 18:33:43 +08:00
|
|
|
#include "AppMacros.h"
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCEventListenerTouch.h"
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2012-10-11 18:33:43 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Scene* HelloWorld::scene()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// 'scene' is an autorelease object
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = Scene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// 'layer' is an autorelease object
|
2012-06-14 15:13:16 +08:00
|
|
|
HelloWorld *layer = HelloWorld::create();
|
2012-04-19 14:35:52 +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 14:17:10 +08:00
|
|
|
if ( !Layer::init() )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-07 14:29:46 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto visibleSize = Director::getInstance()->getVisibleSize();
|
|
|
|
auto origin = Director::getInstance()->getVisibleOrigin();
|
2012-04-19 14:35:52 +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-08-16 16:05:27 +08:00
|
|
|
auto closeItem = MenuItemImage::create(
|
2012-04-19 14:35:52 +08:00
|
|
|
"CloseNormal.png",
|
|
|
|
"CloseSelected.png",
|
2013-06-25 07:59:00 +08:00
|
|
|
CC_CALLBACK_1(HelloWorld::menuCloseCallback,this));
|
2012-08-16 10:21:15 +08:00
|
|
|
|
2013-07-31 14:38:50 +08:00
|
|
|
closeItem->setPosition(origin + Point(visibleSize) - Point(closeItem->getContentSize() / 2));
|
2013-09-16 16:22:22 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// create menu, it's an autorelease object
|
2013-08-16 16:05:27 +08:00
|
|
|
auto menu = Menu::create(closeItem, NULL);
|
2013-07-24 06:20:22 +08:00
|
|
|
menu->setPosition(Point::ZERO);
|
|
|
|
this->addChild(menu, 1);
|
2013-09-03 18:22:03 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/////////////////////////////
|
|
|
|
// 3. add your codes below...
|
|
|
|
|
|
|
|
// add a label shows "Hello World"
|
|
|
|
// create and initialize a label
|
2012-10-11 18:33:43 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto label = LabelTTF::create("Hello World", "Arial", TITLE_FONT_SIZE);
|
2012-10-11 18:33:43 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// position the label on the center of the screen
|
2013-07-24 06:20:22 +08:00
|
|
|
label->setPosition(Point(origin.x + visibleSize.width/2,
|
|
|
|
origin.y + visibleSize.height - label->getContentSize().height));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// add the label as a child to this layer
|
2013-07-24 06:20:22 +08:00
|
|
|
this->addChild(label, 1);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// add "HelloWorld" splash screen"
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("HelloWorld.png");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// position the sprite on the center of the screen
|
2013-07-31 14:38:50 +08:00
|
|
|
sprite->setPosition(Point(visibleSize / 2) + origin);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// add the sprite as a child to this layer
|
2013-09-03 18:22:03 +08:00
|
|
|
this->addChild(sprite);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void HelloWorld::menuCloseCallback(Object* sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-09-12 17:31:37 +08:00
|
|
|
Director::getInstance()->end();
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
|
|
exit(0);
|
|
|
|
#endif
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|