Jump to content

Enabling each property individually in group


Monster9800
 Share

Recommended Posts

Hey, I've got again problem.

I have done respwan my monsters: 

function createMonster() {
        if(nextMonster>game.time.now)
        { return; }
        else {
            var monster = monsters.getFirstExists(false);
            if (monster) {
                monster.hp = 2;
                monster.velocityx = -50;
                monster.reset(ufo.x, ufo.y + 70);
            }
        }
        nextMonster = game.time.now + 4000;
}

Update: 

game.time.events.add(Phaser.Timer.SECOND * 4, createMonster, this);
        monsters.forEachAlive(function velocit (monster) {
            if(hitPlatform){
                monster.body.velocity.x = monster.velocityx;
            }
        });

In my game monster falls down and if colide with platform gets speed.

At first all it's ok, but next monsters gets speed at the time of fall.

 

How can I solve my problem?

 

PS.

My create group code:

        monsters = game.add.group();
        monsters.enableBody = true;
        monsters.physicsBodyType = Phaser.Physics.ARCADE;
        monsters.createMultiple(20, 'monster');
        monsters.callAll('anchor.setTo', 'anchor', 0.5, 1.0);

 

Link to comment
Share on other sites

my guess is that either hitPlatform is not reset to false, which results in all your group objects having -50 velocity... or you are setting the velocity of all your group objects when your using monsters.forEachAlive()... try console.log(monsters) and inspect your monster sprites, its probably because they all have -50 velocity in x direction.
If  you want your monsters to move only when colliding with platform, then you can do something like this (mostly your code):

here you are using the collide function with callBacks when colliding. The createMonster() is now called via A loop event set in create() instead of .add in update().

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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