Sign in to follow this  
karneekarnay

Accessing a Group & Key Events

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?

 

 

 

Share this post


Link to post
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.

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.