Saturday, 7 September 2013

Javascript array splice in animation

Javascript array splice in animation

I'm currently working on a map generator in canvas.
Here is the code working code : http://jsfiddle.net/RtPmm/
and the piece that raise an issue :
MapBuilder = function(){
...
this.checkPath = function(){
...
(logic condition ...) {
var i = Game.builders.indexOf(this);
Game.builders.splice(i,1); /!\
}
and in the render function :
for (var i = 0, len = Game.builders.length; i < len; i++) {
Game.builders[i].checkPath();
}
My problem is that when my MapBuilder objects are supposed to be remove
from the array, the animateloop function still find deleted index when it
iterate throughGame.builders array.
I can't really find this out..
Thanks for taking the time to leave an answer (or comment)

No comments:

Post a Comment