Cocos2d-x learning notes (2) Basic concepts and text

Source: Internet
Author: User

In the cocos2d-x engine, there are several concepts: the Director (CCDirector) in the cocos2d-x engine, the director class is the game organizer and leader, the Director sets rules to make the scene inside the game, set, and the orderly running camera (CCCamera) of the character role, each node needs to use a camera. When the node scales, rotates, and positions change, it needs to overwrite the camera, let this node be re-rendered through the camera. Scenario (CCScene) in a game, a scenario is a level. A level has a set of characters and backgrounds. In terms of concept, a set is a background in a scenario, but it is actually a level concept, this concept exists in the kjava era, that is, to manually layer the scenes in the game (or implement this function using the map editor) of course, including the hero, enemy, npc, organs and other actions (CCAction), is the genie (CCSprite) has the action of the zookeeper cocos2d-x to add the text of the three ways (CCLabelTTF, CCLabelAtlas, and CCLabelBMFont) You can add the following characters to the layer or Sprite: [cpp] <span style = "font-size: 12px;"> CCLabelTTF * pLabel = CCLabelTTF :: create ("Hello World", "Arial", 24); CC_BREAK_IF (! PLabel); // Get window size and place the label upper. CCSize size = CCDirector: shareddire()-> getWinSize (); pLabel-> setPosition (ccp (size. width/2, size. height-50); // Add the label to HelloWorld layer as a child layer. this-> addChild (pLabel, 1); </span> parameter 1: required text parameter 2: Required font parameter 3: font size common functions: each time setStringCCLabelTTF calls setString (that is, changing the text), a new OPENGL texture will be created, which means that setString is as slow as creating a new tag. Therefore, when you need to update them frequently, try not to use tag objects. Instead, you should use CCLabelAtlas or CCLabelBMFont CCLabelAtlas: [cpp] <span style = "font-size: 12px;"> CCLabelAtlas * pAtlas = CCLabelAtlas: create ("0123456789 ", "labelatlas.png", 16,24 ,'. '); pAtlas-> setPosition (ccp (size. width/2, size. height-80); this-> addChild (pAtlas, 1); </span> parameter 1: required text parameter 2: character image file parameter 3: character width parameter 4: character height parameter 5: Set the starting character of the image file to display the frame rate number in the lower left corner of the sample code (HelloWorld, because the frame rate keeps changing, it is too inefficient to use CCLabelTTF because it is only a number. Use CCLabelBMFont to load such a large text image. CCLabelBMFont: [cpp] <span style = "font-size: 12px;"> CCLabelBMFont * pBMFont = CCLabelBMFont: create ("HelloWorld", "dmTest. fnt "); pBMFont-> setScale (0.8f); pBMFont-> setPosition (ccp (size. width/2, size. height-120); this-> addChild (pBMFont, 1); </span> <span style = "font-size: 12px;"> </span> parameter 1: text parameter 2 to be displayed: font coordinate file (*. fnt) commonly used function setScale (float); this function can not specify the font size, but you can use the scale attribute to adjust the size .. You can use the angelCode tool to complete the fnt file in windows.

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.