Apoptyzm Posted May 3, 2014 Share Posted May 3, 2014 Hi,i can't get group.forEach methods to work. Everytime i call them, callback method receives only one null. I tried it on different groups in different parts of the code(just after reset/revive) without any luck. Player.prototype.onClick03 = function () { FloorBuilder.group.forEachExists(this.onClick03Callback(), this); };Player.prototype.onClick03Callback = function (floor) { console.log("tick");//gets called only once if (floor == null) { console.log("onClick03Callback error no floor"); return false;//always ends here once }}My groups always have atleast 10 alive sprites, that i can see in game. This is my little example:function testmethod() { game.load.image("empty", 'img/fish.png'); var physengine = game.physics.arcade; var group = game.add.group(); //create for (var i = 0; i < 5; i++) { var c = group.create(i, //x i * 2, //y 'empty'//floor name random ); //console.log('adding: '+ c.key); c.name = 'testfloor'; physengine.enable(c); c.body.allowGravity = false; c.body.immovable = true; c.body.checkCollision.left = false; c.body.checkCollision.right = false; c.body.checkCollision.down = false; c.kill(); if (c.exists) { console.log("bug"); } } //add to game for (var i = 0; i<5; i++) { console.log("t"); var c = group.getFirstDead(); c.reset(i * c.width, 300 - c.height); c.body.immovable = true; c.body.checkCollision.left = false; c.body.checkCollision.right = false; c.body.checkCollision.down = false; }//works until this line group.forEachExists(player.onClick03Callback(), null);//group.forEachAlive(player.onClick03Callback(), null);}Player.prototype.onClick03Callback = function (floor) { console.log("floor check tick");// :< if (floor == null) { console.log("onClick03Callback error no floor"); return false; }}What am i doing wrong? Link to comment Share on other sites More sharing options...
Pedro Alpera Posted May 4, 2014 Share Posted May 4, 2014 Could be this? group.forEachExists(player.onClick03Callback(), null);togroup.forEachExists(player.onClick03Callback, null); Massemassimo 1 Link to comment Share on other sites More sharing options...
Apoptyzm Posted May 4, 2014 Author Share Posted May 4, 2014 yes that was it, i wasted all saturday because of (). Massemassimo 1 Link to comment Share on other sites More sharing options...
Recommended Posts