cocos2d programming guide翻译(12)

http://bbs.tairan.com/thread-807-1-1.html

 

导演
缓冲
信息支持cocos2d v0.99.4和更新的版本
颜色缓冲
这个默认的缓冲时RGB565.它是一个16位的缓冲器,没有alpha(应该是一种cpu架构).为了使用RGBA8颜色换chogn,你需要创建并初始化EAGLView
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                                                                   pixelFormat:kEAGLColorFormatRGBA8];
kEAGLColorFormatRGBA8:创建一个RGBA8颜色缓冲(32位)
kEAGLColorFormatRGB565:创建一个RGB565颜色缓冲(16位)。更快的,但是没有alpha

深度缓冲
默认情况下,cocos2d不使用深度缓冲,但是你可以创建一个当你初始化EAGLView用一个16位或者24位深度缓冲
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                                               pixelFormat:kEAGLColorFormatRGBA8
                                           depthFormat:GL_DEPTH_COMPONENT24_OES];
GL_DEPTH_COMPONENT24_OES:24位深度缓冲
GL_DEPTH_COMPONENT16_OES:16位深度缓冲
0:没有深度缓冲被创建

高资源
自从v0.99.4开始,导演可以设置颜色来呈递缓冲再高资源模型里:
// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if ([UIScreen instancesRespondToSelector:@selector(scale)])
        [director setContentScaleFactor:[[UIScreen mainScreen] scale]];
从v0.99.5开始,开始支持视网膜屏幕显示:
// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
        CCLOG(@"Retina Display Not supported");
它是怎么工作的:
如果你有一台iphon4,显示方案是960*640

多点抽样,或者全屏Anti_Aliasing
多点抽样可以执行在所有的设备上,但是在MBX设备中表现的冲击力更剧烈
怎么使用它
不要使用CC_DIRECTOR_INIT() macro。可以用下面的例子作为一个简单的模型
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
        // Init the window
        window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        // must be called before any other call to the director
        [CCDirector setDirectorType:kCCDirectorTypeDisplayLink];

        // before creating any layer, set the landscape mode
        CCDirector *director = [CCDirector sharedDirector];

        // landscape orientation
        [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];

        // set FPS at 60
        [director setAnimationInterval:1.0/60];

        // Display FPS: yes
        [director setDisplayFPS:YES];

        // Create an EAGLView with a RGB8 color buffer, and a depth buffer of 24-bits
        EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
                   pixelFormat:kEAGLColorFormatRGBA8                // RGBA8 color buffer
                   depthFormat:GL_DEPTH_COMPONENT24_OES   // 24-bit depth buffer
                   preserveBackbuffer:NO
                   sharegroup:nil //for sharing OpenGL contexts between threads
                   multiSampling:NO //YES to enable it
                   numberOfSamples:0 //can be 1 - 4 if multiSampling=YES
        ];

        // attach the openglView to the director
        [director setOpenGLView:glView];

        // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
        if( ! [director enableRetinaDisplay:YES] )
                CCLOG(@"Retina Display Not supported");

        // make the OpenGLView a child of the main window
        [window addSubview:glView];

        // make main window visible
        [window makeKeyAndVisible];        

        // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
        // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
        // You can change anytime.
        [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];        

        // create the main scene
        CCScene *scene = [...];

        // and run it!
        [director runWithScene: scene];

        return YES;
}
 
 
 
 

posted on 2015-03-14 14:19  沉淀2014  阅读(185)  评论(0编辑  收藏  举报

导航