HelloWorldScene.cpp
1 |
//
|
---|---|
2 |
// HelloWorldScene.cpp
|
3 |
// Untitled
|
4 |
//
|
5 |
// Created by YQ on 11-10-17.
|
6 |
// Copyright __MyCompanyName__ 2011. All rights reserved.
|
7 |
//
|
8 |
|
9 |
#include "HelloWorldScene.h" |
10 |
|
11 |
USING_NS_CC; |
12 |
|
13 |
CCScene* HelloWorld::scene()
|
14 |
{ |
15 |
// 'scene' is an autorelease object
|
16 |
CCScene *scene = CCScene::node(); |
17 |
|
18 |
// 'layer' is an autorelease object
|
19 |
HelloWorld *layer = HelloWorld::node(); |
20 |
|
21 |
// add layer as a child to scene
|
22 |
scene->addChild(layer); |
23 |
|
24 |
// return the scene
|
25 |
return scene;
|
26 |
} |
27 |
|
28 |
// on "init" you need to initialize your instance
|
29 |
bool HelloWorld::init()
|
30 |
{ |
31 |
//////////////////////////////
|
32 |
// 1. super init first
|
33 |
if ( !CCLayer::init() ) |
34 |
{ |
35 |
return false; |
36 |
} |
37 |
|
38 |
/////////////////////////////
|
39 |
// 2. add a menu item with "X" image, which is clicked to quit the program
|
40 |
// you may modify it.
|
41 |
|
42 |
// add a "close" icon to exit the progress. it's an autorelease object
|
43 |
CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage( |
44 |
"CloseNormal.png",
|
45 |
"CloseSelected.png",
|
46 |
this,
|
47 |
menu_selector(HelloWorld::menuCloseCallback) );
|
48 |
pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) ); |
49 |
|
50 |
// create menu, it's an autorelease object
|
51 |
CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL); |
52 |
pMenu->setPosition( CCPointZero ); |
53 |
this->addChild(pMenu, 1); |
54 |
|
55 |
/////////////////////////////
|
56 |
// 3. add your codes below...
|
57 |
|
58 |
// add a label shows "Hello World"
|
59 |
// create and initialize a label
|
60 |
CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 34); |
61 |
|
62 |
// ask director the window size
|
63 |
CCSize size = CCDirector::sharedDirector()->getWinSize(); |
64 |
|
65 |
// position the label on the center of the screen
|
66 |
pLabel->setPosition( ccp(size.width / 2, size.height - 20) ); |
67 |
|
68 |
// add the label as a child to this layer
|
69 |
this->addChild(pLabel, 1); |
70 |
|
71 |
// add "HelloWorld" splash screen"
|
72 |
CCSprite* pSprite = CCSprite::spriteWithFile("HelloWorld.png"); |
73 |
|
74 |
// position the sprite on the center of the screen
|
75 |
pSprite->setPosition( ccp(size.width/2, size.height/2) ); |
76 |
|
77 |
// add the sprite as a child to this layer
|
78 |
this->addChild(pSprite, 0); |
79 |
|
80 |
|
81 |
a = CCMenuItemImage::itemFromNormalImage(
|
82 |
"CloseNormal.png",
|
83 |
"CloseSelected.png",
|
84 |
this,
|
85 |
menu_selector(HelloWorld::test));
|
86 |
menu2 = CCMenu::menuWithItems(a, NULL); |
87 |
menu2->setPosition(CCPointZero); |
88 |
addChild(menu2, 1);
|
89 |
a->setPosition(ccp(30, 30)); |
90 |
menu2->setIsTouchEnabled(false);
|
91 |
return true; |
92 |
} |
93 |
|
94 |
void HelloWorld::menuCloseCallback(CCObject* pSender) |
95 |
{ |
96 |
menu2->setIsTouchEnabled(false);
|
97 |
menu2->setIsTouchEnabled(true);
|
98 |
menu2->setIsTouchEnabled(false);
|
99 |
} |
100 |
void HelloWorld::test(CCObject* pSender) |
101 |
{ |
102 |
|
103 |
} |