我正在研究关于cocos2d理解基本概念的第一个教程。我正在尝试将背景颜色从默认(黑色)更改为白色。这是我的代码:
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface GameScene : CCLayerColor {
CCSprite *player;
}
+(id) scene;
@end
并且实施在这里:
#import "GameScene.h"
@implementation GameScene
+(id) scene
{
CCScene *scene = [CCScene node];
CCLayer *layer = [CCLayer node];
[scene addChild:layer];
return scene;
}
-(id) init
{
if ((self=[super initWithColor:ccc4(255, 255, 255, 255)])) {
self.isAccelerometerEnabled=YES;
player= [CCSprite spriteWithFile:@"Icon-72.png"];
CGSize screenSize=[[CCDirector sharedDirector] winSize];
float imageHeight=[player texture].contentSize.height;
player.position=CGPointMake(screenSize.width/2, imageHeight/2);
[self addChild:player z:0 tag:123];
}
return self;
}
-(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
CGPoint pos=player.position;
pos.x+=acceleration.x*10;
player.position=pos;
}
- (void)dealloc {
[super dealloc];
}
@end
有什么建议吗?感谢
答案 0 :(得分:0)
CCDirectory只接受CCScenes。所以很有可能你遇到的黑屏并不是一个有缺陷的CCColorLayer,而只是空白阶段。
将CCScene子类化为GameScene,然后将CCLayerColor添加到具有所需颜色的CCLayerColor以及播放器。然后拨打[[CCDirector sharedDirector] runWithScene:gameScene]
。