Game Development Reference
In-Depth Information
The opaque flag is set to NO , and the glClearColor is all zero. It's not strictly ne-
cessary to use a black color however; it's sufficient to reduce the alpha channel (fourth
parameter) of glClearColor so that the clear color is at least somewhat transparent.
But for this example and in most cases, you don't want the background to be tinted or
just partially opaque. You may also wonder why setting the view's opaque property
to NO isn't enough to make the view transparent. The answer is simple: OpenGL ES
doesn't respect that property and draws its clear color anyway.
This is only half of the story. What's easy to forget and something you just have to
know is that cocos2d's CCGLView has to be set up with a pixelFormat that actu-
ally uses an alpha channel. Without the alpha channel, you can't make the cocos2d
view transparent.
By default, cocos2d initialized the CCGLView with the kEAGLColor-
FormatRGB565 pixel format. This pixel format uses 16 bits per pixel and has no al-
pha channel. The only other pixelFormat currently supported is kEAGLColor-
FormatRGBA8 , which has 8 bits per color channel plus an 8-bit alpha channel, which
results in 32 bits per pixel. Obviously, this has an impact on performance and memory
usage because the framebuffer memory size doubles. That's the reason why the
kEAGLColorFormatRGB565 pixel format is the default, but there's really no other
choice than to use kEAGLColorFormatRGBA8 if you want to make the cocos2d
view transparent.
Open the AppDelegate.m file, and in the applicationDidFinishLaunch-
ing method look for the line that initialized the CCGLView . Then change that to use
the kEAGLColorFormatRGBA8 pixel format:
CCGLView *glView = [CCGLView viewWithFrame:[window bounds]
pixelFormat: kEAGLColorFormatRGBA8
depthFormat:0];
Kobold2D users can make that change in the config.lua file by changing the
GLViewColorFormat setting accordingly:
GLViewColorFormat = GLViewColorFormat.RGBA8888,
Search Nedrilad ::




Custom Search