Jump to content

How do I access an object/sprite in a group?

James W

Recommended Posts

Hi Guys,

Complete phaser noob and JS amateur!!

Probably an easy answer but how do I access a sprite having created it in a group? I'm not sure which sprite the user will choose first, second etc but need to be able to access the chosen sprites x,y coordinates as well as it's index in the group so I can disable input on that sprite. Hope this makes sense:)

My code:

//create sprite

  randNum = game.rnd.integerInRange(1,9);
  sheep = game.add.group();
  sheep.enableBody = true;

  for (i = 0; i < randNum; i++){

   randX = game.rnd.integerInRange(10,460);
   randY = game.rnd.integerInRange(150,540);

   var lamb = sheep.create(randX,randY,'sheep');

   lamb.inputEnabled = true;



I would like to do something like this in the dragStop event:

function dragStop(){
 if (lamb.x > 500 && lamb.x < 750){


      lamb.inputEnabled = false;






Link to comment
Share on other sites


  • Recently Browsing   0 members

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