CCSprite *sprite = [CCSpritespriteWithFile:@"ImageFileName.png"];
默认锚点 ccp(0.5,0.5),
默认位置 ccp(0,0),
CCSprite尺寸(contentSize)为图片尺寸
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"MineSweeping.plist"]; CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"ImageFileName.png"];
CCSprite *sprite = [CCSprite spriteWithFile:@"ImageFileName.png" rect:CGRectMake(x,y,w,h)];
只显示图片的一部分,大小为 w,h
iOS设备的贴图尺寸必须符合“2的n次方” 规定,所以贴图的宽和高必须是2,4,8,16,32,64,128,256,512,1024. 在第三代设备上可以达到2048像素
[self addChild:sprite];
[s setPosition:ccp(x,y)]; //设置精灵左下角坐标是x=100,y=100,本地GL坐标系 sprite.position=ccp(100,100);
sprite.scale=2;//放大2倍
sprite.rotation=90;//旋转90度
sprite.opacity=255;//设置透明度为完全不透明(范围0~255)
sprite.anchorPoint=ccp(0,0);//设置锚点为左下角,默认为ccp(0.5,0.5)中心点
[sprite setFlipX:YES];//X轴镜像反转
[sprite setFlipY:YES];//Y轴镜像反转
[sprite setVisible:NO];//设置隐藏,默认为可见
[sprite setColor:ccc3(255, 0, 0)];//设置颜色为红色,三原色
[sprite zOrder]; //精灵层叠次序即Z轴(小的在下面,大的在上面),注意这是只读属性,不能通过sprite.zOrder=2实现Z轴重设
[sprite setTextureRect:CGRectMake(10, 10, 30, 30)];//起始点坐标(做上角坐标系),宽高
CCSprite *s1 = [CCSprite spriteWithFile:@"Icon.png"]; CCSprite *s2 = [CCSprite spriteWithFile:@"Icon.png"];
[s1 addChild:s2];
[self reorderChild:sprite z:10];//self为CCLayer或者CCNode
CCTexture2D * texture =[[CCTextureCache sharedTextureCache] addImage: @"Default.png"];//新建贴图
[sprite setTexture:texture]; //更换贴图
利用帧替换
(1)加载帧缓存
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"MineSweeping.plist"];
(2)从帧缓存中取出Default.png
CCSpriteFrame* frame2 = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"Default.png"];
[sprite setDisplayFrame:frame2];
-(void)spriteMoveFinished:(id)sender {
CCSprite *sprite = (CCSprite *)sender;
[self removeChild:sprite cleanup:YES];
}
CCSpriteBatchNode* batch = [CCSpriteBatchNode batchNodeWithFile:@"bullet.png"];
[self addChild:batch];
for (int i = 0; i < 100; i++)
{
CCSprite* sprite = [CCSprite spriteWithFile:@"bullet.png"];
[batch addChild:bullet];
}
CCSprite* sprite = [CCSprite spriteWithFile:@"bullet.png"];
[batch addChild:bullet];
来源:http://group.cnblogs.com/topic/68312.html