Game Development Reference
In-Depth Information
The way to fix this and enable proper rendering of overlapping sprites is to initialize
cocos2d in a different way from how the cocos2d Application template in Xcode sets
things up. It initializes cocos2d in a standard way, which is fine for most games but
fails to work properly with isometric tilemap games. In the IsoTilemap01 project, the
cocos2d startup code is altered to the code in Listing 11-1 with the changes and addi-
tions highlighted in bold.
Listing 11-1. Manually Initializing cocos2d's EAGLView
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Create the main window
window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Create an CCGLView with a RGB565 color buffer, and a depth buffer of 24-bits
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGB565
depthFormat: GL_DEPTH_COMPONENT24_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
director_ = (CCDirectorIOS*)[CCDirector sharedDirector];
[director_setProjection:kCCDirectorProjection2D];
...
You have to change two things for isometric tilemaps. First, you need to enable the
OpenGL depth buffer to allow a more fine-grained control over the z-ordering of ob-
jects. Second, CCDirector has to use a 2D projection to work with the depth buffer.
Tip If you're a Kobold2D user, you can make these changes in the con-
fig.lua file. Look for the GLViewDepthFormat and Enable2DProjection set-
tings and change them to these values:
GLViewDepthFormat = GLViewDepthFormat.Depth24Bit,
Enable2DProjection = YES,
 
 
Search Nedrilad ::




Custom Search