給cocos-2d的場景設置背景顏色

-(void) directorDidReshapeProjection:(CCDirector*)director
{
if(director.runningScene == nil) {
// Add the first scene to the stack. The director will draw it immediately into the framebuffer. (Animation is started automatically when the view is displayed.)
// and add the scene to the stack. The director will run it when it automatically when the view is displayed.
[director runWithScene: [IntroLayer scene]];
}
}
@end


在AppDelegate.m對場景進行初始化時,導演類會跳轉到場景→IntroLayer scene


這個場景是在IntroLayer裏新建的類型爲CCScene

+(CCScene *) scene

這個場景會一閃而過,這個文件的最下面有個onEnter的實例方法,會直接跳轉到另一個場景→HelloWorldLayer scene


在HelloWorldLayer初始化時,init

-(id) init

{

// always call "super" init

// Apple recommends to re-assign "self" with the "super's" return value

if( (self=[super initWithColor:(ccc4(255,0,0,150))])) {

    ......

    }


return self;

}


這裏的if( (self=[super initWithColor:(ccc4(255,0,0,150))])) {

             ......

會設置背景顏色!


發佈了34 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章