Skip to content

Commit 05ce6f6

Browse files
committed
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.
1 parent 56d1cef commit 05ce6f6

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/tilemap/Tilemap.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,28 @@ Phaser.Tilemap.prototype = {
883883

884884
},
885885

886+
/**
887+
* Turn off/on the recalculation of faces for tile or collission updates.
888+
* setPreventRecalculate(true) puts recalculation on hold while
889+
* setPreventRecalculate(false) recalculates all the changed layers.
890+
*
891+
* @method Phaser.Tilemap#setPreventRecalculate
892+
* @param {boolean} if true it will put the recalculation on hold.
893+
*/
894+
setPreventRecalculate: function (value) {
895+
if((value===true)&&(this.preventingRecalculate===false)){
896+
this.preventingRecalculate = true;
897+
this.needToRecalculate = {};
898+
}
899+
if((value===false)&&(this.preventRecalculate===true)){
900+
this.preventingRecalculate = false;
901+
for(var i in this.needToRecalculate){
902+
this.calculateFaces(i);
903+
}
904+
this.needToRecalculate = false;
905+
}
906+
}
907+
886908
/**
887909
* Internal function.
888910
*
@@ -892,6 +914,11 @@ Phaser.Tilemap.prototype = {
892914
*/
893915
calculateFaces: function (layer) {
894916

917+
if(this.preventingRecalculate===true){
918+
this.needToRecalculate[layer] = true;
919+
return;
920+
}
921+
895922
var above = null;
896923
var below = null;
897924
var left = null;

0 commit comments

Comments
 (0)