Operations on Genie and images in cocos2d

Source: Internet
Author: User

Summarize the various operations of the genie for future review.

Brief description:

1. initialize 2. Create a paintless Paster. 3. Set the paintsize. 4. Add the paintless Paster to the layer.

5. Scale the genie 6. Scale the genie or height 7. Rotate the genie

8. Set the sprite transparency 9. Reverse the sprite image 10. Set the sprite color.

11. Obtain the width and height of the image 12, set the image size by Pixel 13, and add XY coordinates on the original base.

14. Set the image anchor 15, arrange the Z axis Order 16, and change the sprite.

17. Set the visible area 18 and the texture to be non-sawtooth.

// Initialization

Ccsprite * sprite = [ccsprite spritewithfile: @ "icon.png"];

// Create an image-less genie

Ccsprite * sprite2 = [ccsprite node];

// Set the sprite size
Sprite2.texturerect = cgrectmake (0, 0, 20, 20); // set it to 20 in width and 20 in height.

// Add an incoming Layer

[Self addchild: sprite z: 2]; // Add the genie to the layer and set its Z axis to 2

// Scale the genie

Sprite. Scale = 2; // enlarge 2 times

// Scale the genie or height

Sprite. scalex = 2; // enlarge the width by 2 times

Sprite. scaley = 2; // 2 times of high magnification

// Rotating genie

Sprite. Rotation = 90; // Rotate 90 degrees

// Sets the sprite transparency.

Sprite. Opacity = 255; // sets the transparency to completely opaque (range: 0 ~ 255)

// Define the genie location

Sprite. Position = CCP (100,100); // set the coordinates of the sprite center to X = 100, y = 100

// Sprite image reversal

[Sprite setflipx: Yes]; // reverse the X axis Image

[Sprite setflipy: Yes]; // the Y axis image is reversed.

// Set the sprite color

[Sprite setcolor: ccc3 (255, 0, 0)]; // set the color to red.

// Obtain the width and height of the image.

Float contentsize = Sprite. contentsize. Width // obtain the width and height of the image.

// Set the image size by Pixel

Sprite. scalex = (20)/contentsize; // custom image width and height based on pixels

// Add XY coordinates on the original base

Sprite. Position = ccpadd (sprite. Position, CCP (20, 20); // add or subtract coordinates based on the original coordinates

// Set the image anchor

[Sprite setanchorpoint: CCP (0.5, 0.5)]; // you can specify the image's anchorpoint.

// Sort the z-axis order

[Self reorderchild: sprite z: 1]; // sort the Z axis order

// Change the sprite texture
Cctexture2d * test = [[cctexturecache sharedtexturecache] addimage: @ "test.png"]; // create a texture

[Sprite settexture: Test];

// Replace the sprite texture and load the frame cache. This test. plist saves the fram image.

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

Ccspriteframe * frame = [[ccspriteframecache sharedspriteframecache] spriteframebyname: @ "fram.png"];
[Sprite2 setdisplayframe: frame];

// Set the visible area
Ccsprite * sprite3 = [ccsprite spritewithfile: @ "icon.png" rect: cgrectmake (0, 0, 20, 20)]; // set at creation

[Sprite3 settexturerect: cgrectmake (10, 10, 30, 30)]; // set it after creation

// The texture is not serticate.

[Sprite3. Texture setaliastexparameters];

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.