Cocos2d-x essay-1

Source: Internet
Author: User

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

}

 

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.