Note that there are some explanatory texts on larger screens.

plurals
  1. POPerformance issue rendering tiles with UIImage imageNamed method
    primarykey
    data
    text
    <p>I have 5 tiles. Each are 16x16 pixels, 8kb in size. They're all loaded using imageNamed. For example, [UIImage imageNamed:@"dirt.png"]. They're loaded outside the drawRect, in the init. I have an array called "map" that maps out where these tiles go. In DrawRect I have a bit of code that renders the stage using two for loops, as shown below.</p> <pre><code>tileNum = startPoint; for(int i = 0; i&lt; stageHeight; i++){ for(int ii = 0; ii&lt; stageWidth; ii++){ if(map[tileNum] == 0){ [dirt drawInRect:CGRectMake(ii*tileSize, i*tileSize, tileSize, tileSize)]; }else if(map[tileNum] ==1){ [tree1 drawInRect:CGRectMake(ii*tileSize, i*tileSize, tileSize, tileSize)]; }else if(map[tileNum] ==2){ [tree2 drawInRect:CGRectMake(ii*tileSize, i*tileSize, tileSize, tileSize)]; }else if(map[tileNum] ==3){ [tree3 drawInRect:CGRectMake(ii*tileSize, i*tileSize, tileSize, tileSize)]; }else if(map[tileNum] ==4){ [tree4 drawInRect:CGRectMake(ii*tileSize, i*tileSize, tileSize, tileSize)]; } tileNum++; } tileNum += (mapWidth - stageWidth); } </code></pre> <p>Everything works awesome in the simulator, just how I want it. But when I put in on the device (3GS) the frame rate slows to a crawl (about 1 frame per second). I suspect it might have to do with the use of imageNamed. Or is it just because I'm rendering too many tiles? (At 16x16 I'm rendering 600 tiles per frame, but they're tiny files and 90% of the tiles drawn are the 'dirt' tile). And if so, what's the better way to create a simple tile engine?</p> <p>This is my first attempt at posting a question. Thanks to anyone who helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload