cocos2dでは画像を貼付ける場合CCSpriteをつかって貼付けます。
画像の配置
CCSpriteをaddChlidします。
CCSprite * image = [CCSprite spriteWithFile:@"Icon.png"];
image.position = ccp(160, 160);
image.tag = 11;
[self addChild:image];
Icon.pngはcocos2dに元々入っているので、上記コードをHelloWorldLayer.mなどに貼付ければそのまま実行できます。
画像の削除
removeChildを使います。
[self removeChild:image cleanup:YES];
画面から画像が消えます。
画像の大きさを指定
rectを指定します。
CCSprite * image1 = [CCSprite spriteWithFile:@"Icon.png" rect:CGRectMake(0, 0, 60, 60)];
image1.position = ccp(160, 160);
image1.tag = 11;
[self addChild:image1];
CGRectMakeでX座標とY座標に0,0を入れないと表示がおかしくなります。