COCOS2DX Study Note 7: Sprite (Sprite)

Source: Internet
Author: User
Tags addchild

Tagged with: Sprite sprite sprite ccsprite cocos2d-x cocos2dx

COCOS2DXof theSpritebytexure,Frameand theAnimationcomposition, byOpenesresponsible for rendering. in the game, the genie is an important concept, the game background,NPC, characters, props and so on. In theCocos2d-xin the engine, as long as the picture is shown, basically need to use the Elf class.

First, Create a wizard common three method of:

direct use of sprite create method to create a

Auto Sprite = sprite::create ("Helloworld.png");// Create an Elf

This->addchild (Sprite, 0);// Add the Elves to the floor.

2. use textures to create sprites

Auto Sprite1 =sprite::createwithtexture (texturecache::getinstance ()->addimage ("Helloworld.png"));

This->addchild (sprite1, 0);//Add elves to the layer

another is the use of sprite frames to create sprites, energy frame animation is mainly used for animation effects, can also be used to create sprites. First we use the texturepacker tool to package the material we use, and here we Package The resources resource picture.

First, drag the picture you want to pack into the software, and then Texture File Location Select the location you want to output and fill in the output file name, click Publis button to package. When the package is complete, a PNG image of the plist file with the same name is exported .

650) this.width=650; "style=" Border-bottom:medium none;border-left:medium none;border-top:medium none;border-right: Medium none; "Title=" Click to view the original "border=" 0 "alt=" study note 7: Figure 1.png "src=" http://www.byjth.com/content/uploadfile/201508/ Thum-42171440669785.png "width=" 650 "height=" 417 "/>

Here we are named Cocosxuexi , the output directory is desktop, and after you click Pack, the file will be generated on the desktop.

650) this.width=650; "style=" Border-bottom:medium none;border-left:medium none;border-top:medium none;border-right: Medium none; "Title=" Click to view the original "border=" 0 "alt=" study note 7: Figure 2.png "src=" http://www.byjth.com/content/uploadfile/201508/ 463f1440670011.png "width=" 263 "height=" 189 "/>

put this 2 files into our resource directory. This call, we first have to load the pliste file before we can call the inside of the helloworld.png file, otherwise there will be no resource errors found.

650) this.width=650; "style=" Border-bottom:medium none;border-left:medium none;border-top:medium none;border-right: Medium none; "Title=" Click to view the original "border=" 0 "alt=" study note 7: Figure 3.png "src=" http://www.byjth.com/content/uploadfile/201508/ Thum-6ec01440670114.png "width=" 650 "height=" 386 "/>

3. use sprite frames to create sprites

Auto Pcache = Spriteframecache::sharedspriteframecache (); // get cache of Spriteframe

Pcache->addspriteframeswithfile ("Cocosxuexi.plist");

Auto Sprite2=sprite::createwithspriteframename ("Helloworld.png");

this->addchild (sprite2, 0);// Add the Elves to the floor.

Three ways to create sprites are created using helloworld.png images. Once created, it can be displayed in the game window.

650) this.width=650; "style=" Border-bottom:medium none;border-left:medium none;border-top:medium none;border-right: Medium none; "Title=" Click to view the original "border=" 0 "alt=" study note 7: Figure 4.png "src=" http://www.byjth.com/content/uploadfile/201508/ 19e31440670183.png "width=" 331 "height=" 511 "/>

This article by closed eyes on the dark finishing editing, reprint please specify: http://www.byjth.com/biji/26.html | Close your eyes on the Dark column _ Original technology blog

This article from "Close your eyes on the Dark" blog, reprint please contact the author!

COCOS2DX Study Note 7: Sprite (Sprite)

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.