如何在ios游戏开发中改变背景颜色?

时间:2014-02-20 06:53:00

标签: ios objective-c cocos2d-iphone

我刚认识cocos2d。我只是想改变背景颜色并想要设置任何图像。我引用This Tutorial.

中的代码

还找不到game-art.plist中所有图片的位置。我找不到他们中的任何一个。只需查看此链接并给我一个合适的答案。

提前致谢。

2 个答案:

答案 0 :(得分:1)

更改背景颜色, 你需要改变:

@interface HelloWorldLayer : CCLayer <.....

为:

@interface HelloWorldLayer : CCLayerColor <.....

然后在HelloWorldLayer.m

变化:

if( (self=[super init]) ) {

为:

if((self = [super initWithColor:ccc4(125,200,255,255)])) /// set ccc4(... as you want
{

将图片添加为BackGround。

CGSize winSize = [[CCDirector sharedDirector] winSize];

CCSprite *background = [CCSprite spriteWithFile:@"background.png"];
background.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:background];

答案 1 :(得分:0)

关注此http://www.ioscreator.com/tutorials/cocos2d-scenes-and-layers

类名:HelloWorldScene

  (id)init {
      self = [super init];
      if (!self) return(nil);
      //create your bg sprite
      CCScene *scene = [CCScene node]; HelloWorld *layer = [HelloWorldLayer node];

      CCSprite *background = [CCSprite spriteWithFile:@"cartoon_landscape.png"]; 
      [layer addChild:background];
  }

按照此处获取更多帮助。 http://www.raywenderlich.com/tag/cocos2d