Cocos2d-x essay-1
# Include "HelloWorldScene. h"
USING_NS_CC;
Scene * HelloWorld: createScene ()
{
// 'Scene 'is an autorelease object
Auto scene = Scene: create ();
// 'Player' is an autorelisted object
Auto layer = HelloWorld: create ();
// Add layer as a child to scene
Scene-> addChild (layer );
// Return the scene
Return scene;
}
All content of this blog is original, if reproduced please indicate the source http://blog.csdn.net/myhaspl/
// On "init" you need to initialize your instance
Bool HelloWorld: init ()
{
//////////////////////////////
// 1. super init first
If (! Layer: init ())
{
Return false;
}
Size visibleSize = Director: getInstance ()-> getVisibleSize ();
Vec2 origin = Director: getInstance ()-> getVisibleOrigin ();
Auto mynode = Node: create ();
/////////////////////////////
// 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
Auto closeItem = MenuItemImage: create (
"CloseNormal.png ",
"CloseSelected.png ",
CC_CALLBACK_1 (HelloWorld: menuCloseCallback, this ));
CloseItem-> setPosition (Vec2 (origin. x + visibleSize. width-closeItem-> getContentSize (). width/2,
Origin. y + closeItem-> getContentSize (). height/2 ));
// Create menu, it's an autorelease object
Auto menu = Menu: create (closeItem, NULL );
Menu-> setPosition (Vec2: ZERO );
Mynode-> addChild (menu, 1 );
/////////////////////////////
// 3. add your codes below...
// Add a label shows "Hello World"
// Create and initialize a label
Auto label = Label: createWithTTF ("myhaspl game", "fonts/Marker Felt. ttf", 24 );
// Position the label on the center of the screen
Label-> setPosition (Vec2 (origin. x + visibleSize. width/2,
Origin. y + visibleSize. height-label-> getContentSize (). height ));
// Add the label as a child to this layer
Mynode-> addChild (label, 1 );
// Add "HelloWorld" splash screen"
Auto sprite = Sprite: create ("HelloWorld.png ");
// Position the sprite on the center of the screen
Sprite-> setPosition (Vec2 (visibleSize. width/2 + origin. x, visibleSize. height/2 + origin. y ));
// Add the sprite as a child to this layer
Mynode-> addChild (sprite, 0 );
Mynode-> setPosition (Point (200,200); // you can specify a position.
Mynode-> setScale (0.5); // sets the scale.
Mynode-> setRotation (90); // sets the rotation.
This-> addChild (mynode); // Add the node
Return true;
}
Void HelloWorld: menuCloseCallback (Ref * pSender)
{
Director: getInstance ()-> end ();
# If (CC_TARGET_PLATFORM = CC_PLATFORM_IOS)
Exit (0 );
# Endif
}