Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Sprite handle - get a sprite by id


kintell33
 Share

Recommended Posts

Hi, im new with phaser and we are in a little project to made a little game. Im trying to develop an sprite handler for call it and said "New man" and generates a random character on the game. Im trying to access to an sprite collection in game or world. The idea its simple, made a GetSpriteById(spriteId) but i cant find any help on the documentation.

 

Thanks to all!

 

PS: Sorry for my bad english!! im from Argentina! =P

Link to comment
Share on other sites

you get the sprite object back from the creation function, so you can keep track of it that way.

 

if you need to locate it later you can walk through the group(s) that it is in. something along the lines of (assuming you're looking for an item with a particular 'name' property in Group 'grp' or one of its descendants/children): 

 

function findNamedItemInGroup( grp, name ){  // capture name in closure, for recursion  var result = (function f( grp )  {    var start = grp.cursor;    var i = start;    do    {      var r;      // recur into Groups      if( i instanceof Phaser.Group )      {        // reset the cursor        grp.cursor = start;        return f( i );      }      else if( i.name === name )      {        // reset the cursor        grp.cursor = start;        return i;      }      grp.next();      i = grp.cursor;    }    while( i && i !== start );    // reset the cursor    grp.cursor = start;    return null;  })( grp );  return result;}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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