How to Implement text rendering of cocos2d-x

Source: Internet
Author: User

[Html]
/1. Create a piece of text
// The three parameters of the create FUNCTION are text content, Font, and font size.
CCLabelTTF * font = CCLabelTTF: create ("Hello World", "48", 48 );
 
// 2. Obtain the text size
// Font-> getContentSize () returns a CCSize value.
// This value has two attributes: width and height, representing the width and height of the text content, respectively.
CCSize fontSize = font-> getContentSize ();
 
// 3. Construct a color
// CcColor3B has three attributes to be set: r, g, and B, which represent the RGB values of the color.
// For example, if r, g, and B are respectively 255, 255, or 255, the color is white.
// The value range of r, g, and B should be [0,255]
// Construct a red string below
CcColor3B color;
Color. r = 255;
Color. g = 0;
Color. B = 0;
 
// 4. Set the font color
// The setColor method of font sets a color for font. The parameter type is ccColor3B.
// Set the color of the previous build to font
Font-> setColor (color );
 
// 5. Set the text transparency
// Set the value of setOpacity to [0,100].
// When the parameter is 0, it indicates completely transparent, that is, invisible
// When the parameter is 100, it indicates that it is not transparent
// The greater the parameter, the clearer it is.
Font-> setOpacity (50 );
 
// 6. Set the text direction
// Font's setFlipX method sets whether the text is flipped horizontally to 180 degrees
// The parameter is boolean. When the parameter is true, the text direction is from right to left.
// Font setFlipY sets whether the text is flipped up vertically to 180 degrees.
// The parameters are also Boolean. If the parameters are true, the text is displayed upside down.
Font-> setFlipX (1 );
Font-> setFlipY (1 );
 
// 7. Obtain the form size
// CCDirector: sharedDirector ()-> getWinSize () can get a CCSize value.
// Its two attributes are the width, width, and height of the form, respectively.
// These two attributes are obtained to facilitate setting the location of text or other controls in the future
CCSize size = CCDirector: shareddire()-> getWinSize ();
 
// 8. Set the text position
// CCPointMake is the definition of CPoint
// Set the font's setPosition Method to the point corresponding to the parameter
// The x and y coordinates of the parameter points correspond to the x and y coordinates of the center position of the rectangle occupied by the text content respectively.
// That is, the parameter point is the center point of the text content
// Place the font in the center of the form below
Font-> setPosition (CCPointMake (size. width/2, size. height/2 ));

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.