First, wizard creation and initialization
1. Create from picture file:
Ccsprite *sprite = [Ccsprite spritewithfile:@ "imagefilename.png"];
Default anchor CCP (0.5,0.5), default position CCP (0,0), ccsprite size (contentsize) for picture size
2. Create from Frame cache:
[[Ccspriteframecache Sharedspriteframecache] addspriteframeswithfile:@ "minesweeping.plist"];
Ccsprite *sprite = [Ccsprite spritewithspriteframename:@ "imagefilename.png"];
3. Initialization and Custom size
Ccsprite *sprite = [Ccsprite spritewithfile:@ "imagefilename.png" Rect:cgrectmake (x,y,w,h)];
Show only part of the picture, size w,h
The map size of the iOS device must conform to the "N-th" 2 rule, so the width and height of the map must be 2,4,8,16,32,64,128,256,512,1024. Up to 2048 megapixels on third-generation devices
Second, the wizard commonly used properties and methods:
Add child node, ccsprite inherit from Ccnode, can do addchild operation
[Self addchild:sprite];
Set Ccsprite location, local GL coordinate system
[s SETPOSITION:CCP (x, y)];
SPRITE.POSITION=CCP (100,100);//Set wizard lower left corner coordinates are x=100,y=100, local GL coordinate system
Zoom (parameter is proportional, 1 remains unchanged, 0.5 means 50%,2 represents 200%)
sprite.scale=2; //magnification twice times
Rotating
sprite.rotation=90; //Rotate 90 degrees
Set Transparency (range 0~255)
sprite.opacity=255;//setting transparency to be completely opaque (range 0~255)
Set Ccsprite anchor Point, lower left corner:
SPRITE.ANCHORPOINT=CCP (0,0);//Set the anchor point to the lower left corner, the default is CCP (0.5,0.5) Center point
Turn on Ccsprite mirroring
[Sprite Setflipx:yes]; //x axis Mirroring inversion
[Sprite Setflipy:yes]; //y axis Mirroring inversion
is visible
[Sprite Setvisible:no]; //Set hide, default is visible
Set the color of the ccsprite (picture)
[Sprite setcolor:ccc3 (255, 0, 0)]; //Set color to red, three primary colors
Stacking order of Ccsprite (small in order below, big on top)
[Sprite ZOrder]; The sprite stacking order is the z axis (small below, large on top), note that this is a read-only property and cannot be reset by sprite.zorder=2 z-axis
Set Texture size
[Sprite Settexturerect:cgrectmake (10, 10, 30, 30)]; //start point coordinate (to do the upper angle coordinate system), width high
Third, add other elves
Ccsprite inherits from the Ccnode, so you can do addchild to it:
Ccsprite *s1 = [Ccsprite spritewithfile:@ "icon.png"];
Ccsprite *s2 = [Ccsprite spritewithfile:@ "icon.png"];
[S1 ADDCHILD:S2];
Four, Genie Z axis reset
[Self reorderchild:sprite z:10]; //self for Cclayer or Ccnode
Five, the wizard to change pictures
1. Replace with the new map directly
Change stickers
CCTEXTURE2D * Texture =[[cctexturecache Sharedtexturecache] AddImage: @ "default.png"]; New Map
[Sprite Settexture:texture];
2. Use frame replacement
Load Frame Cache
[[Ccspriteframecache Sharedspriteframecache] addspriteframeswithfile:@ "minesweeping.plist"];
Remove the Default.png from the frame cache
ccspriteframe* frame2 = [[Ccspriteframecache Sharedspriteframecache] spriteframebyname:@ "Default.png"];
[Sprite Setdisplayframe:frame2];
VI. Remove Sprite:
-(void) spritemovefinished: (ID) Sender {
Ccsprite *sprite = (Ccsprite *) sender;
[Self removechild:sprite cleanup:yes];
}
Seven, Sprite batch processing (Sprite batching):
Create multiple Ccsprite nodes and add them to the same ccspritebatchnode to increase rendering speed
ccspritebatchnode* batch = [Ccspritebatchnode batchnodewithfile:@ "bullet.png"];
[Self addchild:batch];
for (int i = 0; i <; i++)
{
ccsprite* Sprite = [Ccsprite spritewithfile:@ "bullet.png"];
[Batch Addchild:bullet];
}
ccsprite* Sprite = [Ccsprite spritewithfile:@ "bullet.png"];
[Batch Addchild:bullet];
When should I use Ccspritebatchnode?
You can use Ccspritebatchnode when you need to display two or more of the same ccsprite nodes. The more ccsprite nodes that are grouped together, the greater the effect of using Ccspritebatchnode
Source: http://www.cocos2dchina.com/archives/323#more-323
Ccsprite use of the method Daquan