Cocos 2D 2.8.2 beta: TMX tile map tests with huge maps.

While devel­op­ing using Cocos 2D (0.8.2 beta) on iPhone i faced some huge per­for­ma­ces prob­lems loading

a map of 9472 tiles (4096px x 592px, 16x16pixels tiles).

The load­ing process took about 1.30 secs on an iPhone 3GS

I’ve done some tests chang­ing % value in row 208 of TMXTiledMap.m:

float capacity = totalNumberOfTiles * 0.35f + 1; // 35 percent is occupied ?

TESTS——————————————————————————

test 1 (orig­i­nal, capac­ity is 35% of #tiles): capac­ity = total­Num­berOfTiles *0.35f +1-> load­ing time: 1.15 secs (4 Tex­ture­At­las chang­ing operations)

test 2 (capac­ity is 100% of #tiles): capac­ity = total­Num­berOfTiles +1 -> load­ing time: 1.25 secs (no Tex­ture­At­las chang­ing operations)

test 3 (capac­ity is 50% of #tiles): capac­ity = total­Num­berOfTiles *0.50f +1 -> load­ing time: 1.20 secs (some Tex­ture­At­las chang­ing operations)

test 4 (capac­ity is only 10% of #tiles): capac­ity = total­Num­berOfTiles *0.10f +1 -> load­ing time: 1.10 secs (8 Tex­ture­At­las chang­ing operations)

/TESTS——————————————————————————

The strange­ness is that set­ting to max value the capac­ity decrease per­for­mances! So it seems that the per­for­mances bot­tle­neck isn’t in mem­ory copy oper­a­tions but some­where else. Prob­a­bly the per­for­mance prob­lem is due to the use of AtlasSprite to contain every tile.

The only solu­tion for now is to load only a sub­set of tiles and replace then when the char­ac­ter moves a some amount of pixels/tiles: in this way the load­ing process decreased to about 5 secs (or less).

UPDATED: after my post on the Cocos2D forum (http://www.cocos2d-iphone.org/forum/topic/2165?replies=12#post-14895) “riq” about this issue, a devel­oper of the project, patched in a day this prob­lem and now to load of these huge maps takes ONLY 1.5secs!!!!

The pacthed ver­sion is avail­able down­load­ing from the google SVN repository.

ps. I don’t know why noone pointed this prob­lem, but now all devel­op­ers will be really happy of this patch version!

Leave a comment

Your comment