Hello,
Allthough the engine runs fast on all computers Iv tested it on, Iv now started optimizing the code to get it to run faster. Then maybe I will be able to use even more particle effects and such. I though ill start posting some code on this blog in case someone is interested.
So, the first thing iv done is to get the main loop faster. It loops through every tile on the map every frame. So if you have a map with 100 horisontal tiles and 100 vertical tiles you have a total of 10 000 tiles, and those are looped through 30 times a second, so 300 000. So to get the main loop faster will make some diffrence.
At first the loop looked like this:
I run each loop 100 times with 100×100 tiles, tileArray is the array holding all the tiles
-
// class Render
-
var e:Element;
-
for (var i:int = 0; i < this.tileArray.length; i++)
-
{
-
for (var u:int = 0; u < this.tileArray[0].length; u++)
-
{
-
e = this.tileArray[i][u] as Element;
-
if (!e.empty)
-
{
-
e.update();
-
}
-
}
-
}
This took: 1842ms
-
// class Render
-
var xlength:int = this.tileArray[0].length;
-
var ylength:int = this.tileArray.length;
-
var e:Element;
-
for (var i:int = 0; i < ylength; i++)
-
{
-
for (var u:int = 0; u < xlength; u++)
-
{
-
e = this.tileArray[i][u] as Element;
-
if (!e.empty)
-
{
-
e.update();
-
}
-
}
-
}
This took: 1520ms, some improvment!
-
// class Render
-
for each(var a:Array in this.tileArray)
-
{
-
for each(var e:Element in a) {
-
if (!e.empty)
-
{
-
e.update();
-
}
-
}
-
}
This is what I ended up with after some testing, and it took 1422ms, a bit faster though the the best part is that the code looks much better
Here is two pages i found about this subject
Seven tips about actionscript optimizing at gamedevjuice.wordpress.com
Optimizing actionscript 3 at www.nbilyk.com