I'm making a quick tile engine with my own collision detection, everything works but i'm facing problems on the last step, applying textures on tiles.
This code refers to the clipping of the tiles on the visible area and runs at 60fps:
// add the visible tiles (SPQuad) for ( int x = 0; x < 5; x++ ){ for ( int y = 0; y < 5; y++ ){ if ((gridX-2)+x <= mapWidth*2 && (gridY-2)+y <= mapHeight*2 && (gridX-2)+x >= 0 && (gridY-2)+y >= 0) { if ([[_mapRows objectAtIndex:(gridX-2)+x] objectAtIndex:(gridY-2)+y] == [NSNumber numberWithInt:0]) { SPQuad *quadTile = [SPQuad quadWithWidth:tileSize height:tileSize]; quadTile.x = (100 * ((gridX-2)+x)); quadTile.y = (100 * ((gridY-2)+y)); [visibleTiles addChild:quadTile]; } } } }
This one walk at 3/4 fps:
// add the visible tiles (SPImage) for ( int x = 0; x < 5; x++ ){ for ( int y = 0; y < 5; y++ ){ if ((gridX-2)+x <= mapWidth*2 && (gridY-2)+y <= mapHeight*2 && (gridX-2)+x >= 0 && (gridY-2)+y >= 0) { if ([[_mapRows objectAtIndex:(gridX-2)+x] objectAtIndex:(gridY-2)+y] == [NSNumber numberWithInt:0]) { SPImage *quadTile = [SPImage imageWithContentsOfFile:@"tile.png"]; quadTile.x = (100 * ((gridX-2)+x)); quadTile.y = (100 * ((gridY-2)+y)); [visibleTiles addChild:quadTile]; } } } }
The only difference is that i'm using a real image instead of a temp SPQuad.
Which is the shortest way to solve this problem? In that cycle i will have to choose an image between no more than other ~15 and add it to the visibleTils sprite.
Thanks in advance!