Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-09-2012, 02:00 AM   #1
Registered User
Join Date: Jan 2012
Posts: 5
Default [AS3] Handling Vector Tiles Efficiently

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:

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;
this is the IsoTile class
 * 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 {
			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;

xslaught is offline   Reply With Quote
Old 05-10-2012, 09:32 PM   #2
throw a trace() in there
Join Date: Dec 2006
Posts: 1,982

A couple thoughts:
1) I don't see anything about hiding the IsoTiles when they are off-screen and showing them on-screen. If most of your four million tiles aren't on-screen you may speed things up if they aren't visible.
2) If the loading's slow, use some temp variables in your loading loop. Like, if you're referencing: "mapXML.map[mapID].layer[l].fill" every time the Flash player is getting: mapXML, then map, then mapID, then using mapID as the index in mapXML.map, then getting layer, then l, then using l as the index in layer, then getting fill. But if you make a tempFill:XMLList (I think?) variable and just assign it once, before the loop, you can cut that down a little.
rrh is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 06:53 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.