sprite基本知識、[縮放,旋轉,透明度,XY翻轉,顏色設置,z值改變,換圖]


 1         CCSprite* sprite=[CCSprite spriteWithFile:@"Icon.png"];
2 [self addChild:sprite z:1 tag:100]; //z 值默認為0;
3 sprite.scale=0.8f;// 縮放;
4 sprite.rotation=90; // 旋轉80度;
5 sprite.opacity=25; //透明度為25 [范圍為0-255];
6 sprite.position=ccp(100, 100); //設置錨點坐標;
7 sprite.flipX=YES;

8 sprite.flipY=YES; //x,y翻轉;
9 sprite.color=ccc3(255, 255, 0); //顏色設置;
10
 1   
2 CCSprite* backGround=[CCSprite spriteWithFile:@"背景.png"];
3 [self addChild:backGround];
4 backGround.position=ccp(200, 200);
5 CCSprite* windows=[CCSprite spriteWithFile:@"窗.png"]; //背景圖蓋窗;
6 [self addChild:windows z:1];

7 windows.position=ccp(250, 250);
 
         

 8         
9 [self reorderChild:backGround z:1]; //通過改變z值,窗蓋背景;
10 [self reorderChild:windows z:0];
 
         


 

 1 CCSprite*sprite1 =[CCSprite spriteWithFile:@"Icon.png"]; 
2 sprite1.position=ccp(400,150);
3 [self addChild:sprite1];
4
5 CCSprite*sprite2 =[CCSprite spriteWithFile:@"Icon.png"]; //沒換圖前;
6 sprite2.position=ccp(400,250);

7 [self addChild:sprite2];
8

 9          CCTexture2D * texture =[[CCTextureCache sharedTextureCache] addImage: @"同學.png"]; //換圖后

10 [sprite1 setTexture:texture]; //換圖,[原精靈尺寸有多大,跟換的貼圖就有多大]
11


12 CCSprite *back = [CCSprite spriteWithFile:@"同學.png"];
13 [sprite1 setDisplayFrame:[CCSpriteFrame frameWithTexture:back.texture rect:back.textureRect]]; //此換圖方法,換圖的sprite是多大,被跟換后的sprite就是多大;
 
          
         

 1         //或者事先添加幀緩存;
2 [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"btn_star_start.plist"];

3 //-----沒有換貼圖前
4 CCSprite*sprite4 =[CCSprite spriteWithFile:@"Icon.png"];

5 sprite4.position=ccp(50,50);
6 [self addChild:sprite4];


7 //-----換貼圖后
8 CCSprite*sprite3 =[CCSprite spriteWithFile:@"Icon.png"];

9 sprite3.position=ccp(150,50);
10 [self addChild:sprite3];
11 //更換幀貼圖
12 //從幀緩存中取出"main.png"
13 CCSpriteFrame* frame2 = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"main.png"];

14 [sprite3 setDisplayFrame:frame2];





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM