Jump to content

Enemy respawn?


deleteme
 Share

Recommended Posts

Update: I did something a little different "function EnemyDemon() {
    var x = game.world.randomX;
    var y = game.world.randomY;
    

    demon = game.add.sprite(x, y, "demon");
    demon.anchor.setTo(0.5, 0.5);
   
    game.physics.arcade.enable(demon);
    demon.body.allowRotation = false;
    demon.body.collideWorldBounds = true;
}

 

function create() {

var enemiesTotal = 40;

 

  demons = [];

 
  for (var index = 0; index < enemiesTotal; index++)
    {
      demons.push(new EnemyDemon(index, game, demon));
    }

}

 

function update() {
  demon.rotation = game.physics.arcade.moveToObject(demon, player, 200);

}

"

and this causes a mess of sprites to appear on screen, but only one of them  actually chases after my player, any idea what i should do?

Link to comment
Share on other sites

Sorry, I should have explained better.

 

What I mean is that demons is your group, demon is just one object. You current code is only moving one sprite, because you're only setting the rotation for demon - not the group.

 

You want to move the whole group, so you'll need to move each member of the demons group. I'm not able to test it out myself right now, but maybe try using the group.setAll method to set the rotation for all children in the group. A less efficient, but possible solution is to loop through each member of the group and set the rotation individually.

 


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...