I am working on a tile system where the game reads an XML file with data and then fills them accordingly with tiles. I found out that if the size of the area I fill is large (6000x6000 for example), the game slows down immensely. It even slows down at 2000x2000. I tried cacheAsBitmap which helps speed up the process while in game but the map still takes awhile to load. I want to deal with large maps and 2000x2000 isn't that big. Is there any better way to handle vector based tiles?
I am creating a new display object for each tile which is an inefficient way to do things but I haven't figured out a way to just reference the vector image while having different x/y/z coordinates for each individual tile.
If I use the same reference to the display object, but give the IsoTile class different x/y/z coordinates, the x/y/z of the display object also changes.
I am using as3isolib is that helps.
This is the code I have:
Code:
for(var m:int = 0; m < mapXML.map[mapID].layer[l].fill.length(); m++) {
// Fills layer with specified tile with specified tile size
var fillX1:int = mapXML.map[mapID].layer[l].fill[m].@x1;
var fillX2:int = mapXML.map[mapID].layer[l].fill[m].@x2;
var fillY1:int = mapXML.map[mapID].layer[l].fill[m].@y1;
var fillY2:int = mapXML.map[mapID].layer[l].fill[m].@y2;
var fillTileWidth:int = mapXML.map[mapID].layer[l].fill[m].@tileWidth;
var fillTileHeight:int = mapXML.map[mapID].layer[l].fill[m].@tileHeight;
for(var fillX:int = fillX1; fillX < fillX2; fillX += fillTileWidth) {
for(var fillY:int = fillY1; fillY < fillY2; fillY += fillTileHeight) {
// Tile
// Get tileID and get matching tile with tileID from isoObjects vector
var fillTileID:int = int(mapXML.map[mapID].layer[l].fill[m].@tile);
var fillTile:IsoObject = Library.instance.isoObject[fillTileID].clone();
// Assign tile position to each tile
fillTile.xPos = fillX;
fillTile.yPos = fillY;
fillTile.zPos = 0;
fillTile.x = fillTile.xPos;
fillTile.y = fillTile.yPos;
fillTile.z = fillTile.zPos;
addChild(fillTile);
}
}
}
this is the IsoTile class
Code:
/*
* IsoTile extends IsoSprite
*/
package xxx {
public class IsoTile extends IsoSprite {
// Image properties
public var img:String;
public var display:MovieClip;
public function IsoTile(objID:int, img:String, xSize:int, ySize:int, zSize:int, collision:Boolean):void {
super();
this.objID = objID;
this.img = img;
this.xSize = xSize;
this.ySize = ySize;
this.zSize = zSize;
this.collision = collision;
this.width = xSize;
this.length = ySize;
this.height = zSize;
if(img) {
display = MovieClip (Library.instance.createInstance(Library.instance.displayObject["Tiles"], tiles."+img, img));
display.cacheAsBitmap = true;
sprites = [display];
}
}
override public function clone():* {
var clone:* = new IsoTile(this.objID, this.img, this.xSize, this.ySize, this.zSize, this.collision);
return clone;
}
}
}