TileMap update performance

Discussion: http://www.html5gamedevs.com/topic/7409-tilemaps-changing/

It should remove the problem of updating stuff in a 100x100 tilemap making the engine recalculate every single update.(390 tiles changed in that map makes it a 100x100x390 loop.
Whould make the recalculate parameter in the setCollision functions unnecessary as well.
This commit is contained in:
sivael 2014-06-27 14:10:11 +02:00
parent 56d1cef1c8
commit 05ce6f60a1

View file

@ -883,6 +883,28 @@ Phaser.Tilemap.prototype = {
},
/**
* Turn off/on the recalculation of faces for tile or collission updates.
* setPreventRecalculate(true) puts recalculation on hold while
* setPreventRecalculate(false) recalculates all the changed layers.
*
* @method Phaser.Tilemap#setPreventRecalculate
* @param {boolean} if true it will put the recalculation on hold.
*/
setPreventRecalculate: function (value) {
if((value===true)&&(this.preventingRecalculate===false)){
this.preventingRecalculate = true;
this.needToRecalculate = {};
}
if((value===false)&&(this.preventRecalculate===true)){
this.preventingRecalculate = false;
for(var i in this.needToRecalculate){
this.calculateFaces(i);
}
this.needToRecalculate = false;
}
}
/**
* Internal function.
*
@ -892,6 +914,11 @@ Phaser.Tilemap.prototype = {
*/
calculateFaces: function (layer) {
if(this.preventingRecalculate===true){
this.needToRecalculate[layer] = true;
return;
}
var above = null;
var below = null;
var left = null;