开发者

not able to change background using CCLayerColor and initWithColor:cc4(255,255,255,255)

开发者 https://www.devze.com 2023-04-09 08:11 出处:网络
i am working on very first tutorial on cocos2d understanding basic concept.I am trying to change background color from default(black) to white.here is my code:

i am working on very first tutorial on cocos2d understanding basic concept.I am trying to change background color from default(black) to white.here is my code:

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface GameScene : CCLayerColor {

    CCSprite *player;
}  
+(id) scene; 
@end

and implementation goes here:

#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.p开发者_StackOverflow中文版osition=pos;  
}
- (void)dealloc {

    [super dealloc];
}
@end

any suggestion? thanks


CCDirectory only takes CCScenes. So most likely the black screen you experience is not a faulty CCColorLayer, but simply the blank stage.

Subclass CCScene as GameScene, then add a CCLayerColor to that with your desired color, as well as your player. Then call [[CCDirector sharedDirector] runWithScene:gameScene].

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号