2012-04-19 14:35:52 +08:00
|
|
|
#include "HelloWorldScene.h"
|
2012-10-11 18:33:43 +08:00
|
|
|
#include "AppMacros.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2012-10-11 18:33:43 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCScene* HelloWorld::scene()
|
|
|
|
{
|
|
|
|
// 'scene' is an autorelease object
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScene *scene = CCScene::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
|
|
|
|
if ( !CCLayer::init() )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-07 14:29:46 +08:00
|
|
|
|
2012-10-11 16:45:14 +08:00
|
|
|
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
|
2012-08-09 10:23:39 +08:00
|
|
|
CCPoint origin = CCDirector::sharedDirector()->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
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
|
2012-04-19 14:35:52 +08:00
|
|
|
"CloseNormal.png",
|
|
|
|
"CloseSelected.png",
|
|
|
|
this,
|
2012-08-07 18:24:45 +08:00
|
|
|
menu_selector(HelloWorld::menuCloseCallback));
|
2012-08-16 10:21:15 +08:00
|
|
|
|
2012-10-11 16:45:14 +08:00
|
|
|
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
|
|
|
|
origin.y + pCloseItem->getContentSize().height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// create menu, it's an autorelease object
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
|
2012-08-07 18:24:45 +08:00
|
|
|
pMenu->setPosition(CCPointZero);
|
2012-04-19 14:35:52 +08:00
|
|
|
this->addChild(pMenu, 1);
|
|
|
|
|
|
|
|
/////////////////////////////
|
|
|
|
// 3. add your codes below...
|
|
|
|
|
|
|
|
// add a label shows "Hello World"
|
|
|
|
// create and initialize a label
|
2012-10-11 18:33:43 +08:00
|
|
|
|
2012-10-23 10:50:47 +08:00
|
|
|
CCLabelTTF* pLabel = CCLabelTTF::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
|
2012-10-11 16:45:14 +08:00
|
|
|
pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
|
|
|
|
origin.y + visibleSize.height - pLabel->getContentSize().height));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// add the label as a child to this layer
|
|
|
|
this->addChild(pLabel, 1);
|
|
|
|
|
|
|
|
// add "HelloWorld" splash screen"
|
2012-06-20 13:56:09 +08:00
|
|
|
CCSprite* pSprite = CCSprite::create("HelloWorld.png");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// position the sprite on the center of the screen
|
2012-10-11 16:45:14 +08:00
|
|
|
pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// add the sprite as a child to this layer
|
|
|
|
this->addChild(pSprite, 0);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-11 18:33:43 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
void HelloWorld::menuCloseCallback(CCObject* pSender)
|
|
|
|
{
|
|
|
|
CCDirector::sharedDirector()->end();
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
|
|
exit(0);
|
|
|
|
#endif
|
|
|
|
}
|