Cocos2d sprite Creation

Source: Internet
Author: User

Ccsprite is the most commonly used class. It uses images to display the Sprite on the screen. There are three ways to create the sprite ):


// 1. Create a file directly through ccspriteGenie

Ccsprite * sprit = [ccsprite spritewithfile: @ "1.jpg"];

Cgsize size = [[ccdirector shareddire] winsize];

Sprit. Position = CCP (size. Width, size. Height );

Sprit. anchorpoint = CCP (1, 1 );

[Self addchild: sprit];

// 2. Use texture to create a genie and store it in the cache

Cctexture2d * Tx = [[cctexturecache sharedtexturecache] addimage: @ "1.jpg"];

Ccsprite * txsprite = [ccsprite spritewithtexture: TX];

Cgsize size = [[ccdirector shareddire] winsize];

Txsprite. Position = CCP (size. width/4, size. Height/4 );

[Self addchild: txsprite];

// Retrieve images from the cache to save memory

Cctexture2d * tx2 = [[cctexturecache sharedtexturecache] textureforkey: @ "1.jpg"];

Ccsprite * txsprite2 = [ccsprite spritewithtexture: tx2];

Txsprite2.position = CCP (size. Width * 3/4, size. Height/4 );

[Self addchild: txsprite2];

// 3. Obtain the image from the texture set

[[Ccspriteframecache sharedspriteframecache] addspriteframeswithfile: @ "untitled_default.plist"];

Ccsprite * sprite = [ccsprite spritewithspriteframename: @ "5.jpg"];

Cgsize size = [[ccdirector shareddire] winsize];

Sprite. Position = CCP (size. width/4, size. Height/4 );

[Self addchild: 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.