Five ways to create a genie in Cocos2d-x

Source: Internet
Author: User

  1. // Five ways to create the genie // Method 1: directly create the genie
  2. // Suitable for all areas of the image to be displayed, CCSprite * sprite = CCSprite: create ("Icon.png ");
  3. // The above sentence can also be written as needed: // CCString * fileName = CCString: createWithFormat ("icon_0000d.jpg", flag );
  4. // CCSprite * sprite = CCSprite: create (fileName-> getCString (); sprite-> setPosition (ccp (100,100 ));
  5. This-> addChild (sprite); // Method 2: parameter image name rectangular area
  6. // Suitable for some areas where the image is to be displayed CCSprite * sprite = CCSprite: create ("Icon.png", CCRectMake (0, 0, 30, 30 ));
  7. Sprite-> setPosition (CP (100,100); this-> addChild (sprite );
  8. // Method 3: claim an object using the frame name in the frame cache // suitable for plist packaged files
  9. CCSpriteFrameCache: sharedSpriteFrameCache ()-> equals ("test_icon.plist"); CCSprite * sprite = CCSprite: createWithSpriteFrameName ("Icon.png ");
  10. Sprite-> setPosition (CP (100,100); this-> addChild (sprite );
  11. // Method 4: Use another frame to generate a genie object // suitable for Frame Animation
  12. CCSpriteFrame * frame = CCSpriteFrame: create ("Icon.png", CCRectMake (0, 0, 40, 30); CCSprite * sprite = CCSprite: createWithSpriteFrame (frame );
  13. Sprite-> setPosition (ccp (310,150); addChild (sprite );
  14. // Method 5: Use texture, // suitable for images that require frequent use
  15. CCSpriteBatchNode * spriteTexture = CCSpriteBatchNode: create ("iocn.png"); spriteTexture-> setPosition (CCPointZero );
  16. AddChild (spriteTexture); CCSprite * sprite = CCSprite: createWithTexture (spriteTexture-> getTexture ());
  17. Sprite-> setPosition (ccp (visiblesize. width/2,100); spriteTexture-> addChild (sprite, 2 );

    Article

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.