CCSprite是最常用到的类。它使用图片把精灵(sprite)显示在屏幕上,精灵的创建(3种方法):
CCSprite *sprit = [CCSprite spriteWithFile:@"1.jpg"];
CGSize size = [[CCDirector sharedDirector] winSize];
sprit.position = ccp(size.width, size.height);
sprit.anchorPoint = ccp(1, 1);
[self addChild:sprit];
CCTexture2D * tx = [[CCTextureCache sharedTextureCache] addImage:@"1.jpg"];
CCSprite * txSprite =[CCSprite spriteWithTexture:tx];
CGSize size = [[CCDirector sharedDirector] winSize];
txSprite.position = ccp(size.width/4,size.height/4);
[self addChild:txSprite];
//从缓存中取得图片,节省内存
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];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Untitled_default.plist"];
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"5.jpg"];
CGSize size = [[CCDirector sharedDirector] winSize];
sprite.position = ccp(size.width/4,size.height/4);
[self addChild:sprite];