2013-04-02 37 views
2

因爲我在整個cocos2d之前完成了遊戲,而且我正在第一次使用UIViewController負責啓動遊戲場景,我想知道我應該怎麼做,因爲appDelegate是以一個普通的UIViewController開始的,我怎麼能在一個按鈕上設置一個方法來啓動遊戲(例如遊戲的第一個場景)?我一直在尋找關於這個例子或討論,但我沒有找到任何東西,我看到的每個例子都是在第一次調用時從appDelegate開始遊戲場景。如何從正在運行的(uiviewcontroller)應用程序啓動一個cocos2d場景

+0

你嘗試設置控制器在啓動時創建的openglview看法? – giorashc

+0

你的意思,而不是設置navController與根主任,並調用與setview的導演:glview我可以做我的自定義視圖控制器相同? – Adarkuccio

+0

從來沒有嘗試過,但你可以給它一個鏡頭。 – giorashc

回答

0

只需導入你的cocos2d layer.h和layer.m文件 並從視圖控制器使用調用下面的代碼: -

if(! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink]) 
     [CCDirector setDirectorType:kCCDirectorTypeDefault]; 


    CCDirector *director = [CCDirector sharedDirector]; 

    EAGLView *glView = [EAGLView viewWithFrame:[self.view bounds] 
    pixelFormat:kEAGLColorFormatRGB565 depthFormat:0]; 

    [director setOpenGLView:glView]; 


    [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft]; 


    [director setAnimationInterval:1.0/60]; 
    [director setDisplayFPS:YES]; 

    [self setView:glView]; 

    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888]; 

    [[CCDirector sharedDirector] runWithScene: [HelloWorldLayer scene]]; 
相關問題