PDA

View Full Version : Tile Based Game - Slow to Load



bojosiri
July 28th, 2009, 12:03 PM
Hi Every1.

The tile based game that i am doing is currently loading 25 x 25 pixel pngs to create the map. The problem i am having with this is that it is taking too long, i.e. circa 30 secs at least. I am loading the tiles via this way:


private function loadBitmaps():void
{
if (_currentId >= _mapArray.length) {
drawMap();
return;
}
if (_loader.content != null) _loader.unload();

_loader.load(new URLRequest(_mapArray[_currentId].img));
_loader.contentLoaderInfo.addEventListener(Event.C OMPLETE,completeTile);
}

private function completeTile(e:Event) {

_mapArray[_currentId].bmp = (_loader.content as Bitmap);
_currentId++;
loadBitmaps();
}



the initial loadBitmap is called once the user chooses the map.
My question is, how can I improve the load speed? Im sure there is a more efficient way to load tiles that correspond to an array.

Thanks for your help.

BoppreH
July 28th, 2009, 01:11 PM
You are probably loading the same images twice.

Create an Object to hold each loaded image's URL and try to get the already loaded values from there.

therobot
July 28th, 2009, 02:09 PM
depending on how many tiles you have, you may want to lump them all into one big tilesheet png. if you're loading each of your tiles sequentially (i.e. load one tile, wait til its done, repeat with next tile), that might slow things down a bit, too.