Jump to content

Accessing a Group & Key Events


karneekarnay
 Share

Recommended Posts

Hi Guys,

 

I have a Phaser Group called enemies that I have so far populated with enemy sprites. What I want to do is accessing them and change their velocity values so they can move backwards and forwards. My code is below. This is from my create(). 

//Create an empty enemy group we can user as a container.
enemies = game.add.group();
//Enable physics on the enemies group
enemies.enableBody = true;

My code for the enemy is below.

function enemyMovement(game, player, platforms, speed, enemies) {
                    
    //  Collide the player and the stars with the platforms
    game.physics.arcade.collide(player, enemies);
    game.physics.arcade.collide(enemies, platforms);
        
    //  Reset the enemies velocity (movement)
    enemies.body.velocity.x = 150;
    
};

 

Also I raised a post earlier about key events but I didn't get any responces. The question for that is below. Any ideas?

 

 

 

Link to comment
Share on other sites

I replied to your key events.

Regarding this one, what is you want to do? Individually set each entity within the group? I'm not a Phaser user but I'd have thought Phaser exposes a method for accessing children, just loop through that array and do what you like to each one. You might also want to apply something to the group as well, as I think you are doing currently.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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