Jump to content

group forEachAlive/Exists not working


Apoptyzm
 Share

Recommended Posts

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...