HelloworldScene. h # ifndef _ HELLOWORLD_SCENE_H __# define _ HELLOWORLD_SCENE_H _ # include "cocos2d. h "class HelloWorld: public cocos2d: CCLayer {public: // initialization function virtual bool init (); // static creation function static cocos2d: CCScene * scene (); // a callback function void menuCloseCallback (CCObject * pSender) in the menu; // Note 1 CREATE_FUNC (HelloWorld);}; # endif // _ HELLOWORLD_SCENE_H _ HelloWorldScene. cpp # include "HelloWorldScene. h "# incl Ude "SimpleAudioEngine. h "using namespace cocos2d; using namespace CocosDenshion; CCScene * HelloWorld: scene () {// create a scenario object CCScene * scene = CCScene: create (); // create a HelloWorld object (Layer layer) HelloWorld * layer = HelloWorld: create (); // put the child who uses the Layer as the scenario into the scenario scene-> addChild (layer ); return scene;} // on "init" you need to initialize your instancebool HelloWorld: init () {// call the parent class initialization function first if (! CCLayer: init () {return false;} // create an "X" image as an image menu item, // bind the callback function after the user clicks to the CCMenuItemImage * pCloseItem = callback: create ("CloseNormal.png", "CloseSelected.png", this, menu_selector (HelloWorld :: menuCloseCallback); // set the position of the menu item pCloseItem-> setPosition (ccp (CCDirector: sharedDirector ()-> getWinSize (). width-20, 20); // Add the created Menu item to the Menu to generate a Menu object instance CCMenu * pMenu = CCMenu: create (pCloseItem, NULL ); // set the menu as CCPointZero: x = 0, y = 0 pMenu-> setPosition (CCPointZero); // Add the menu to the current Layer, and set the Z axis to 1 this-> addChild (pMenu, 1); // create a Text object CCLabelTTF * pLabel = CCLabelTTF: create ("Hello World", "Thonburi ", 34); // get the current device size, CCSize size = CCDirector: sharedDirector ()-> getWinSize (); // set the text coordinate pLabel-> setPosition (ccp (size. width/2, size. height-20); // Add the text to the current Layer this-> addChild (pLabel, 1); // use the HelloWorld.png image to create a Sprite * pSprite = CCSprite :: create ("HelloWorld.png"); // set the sprite position pSprite-> setPosition (ccp (size. width/2, size. height/2); // place the genie in the current layer this-> addChild (pSprite, 0); return true;} voidHelloWorld: menuCloseCallback (CCObject * pSender) {// exit CCDirector: shareddire()-> end (); // determine whether the current device is an ios device # if (CC_TARGET_PLATFORM = CC_PLATFORM_IOS) exit (0 ); # endif}