Jump to content

Create objects in groups - Need to be sprites?


Langusmon
 Share

Recommended Posts

I am creating a game that is similar to a board game, and am somewhat new to phaser. I created a 'Players' group (players = game.add.group();) , created a sprite for each player and added them into the group. The sprites have an X,Y but no image assign to them, so nothing actually shows up on the game board for the players, but not I can account for them, assign and update properties, etc. 

For objects in the game that are not image based, is this the correct way of creating / managing these objects or is there a better way to go about this?

Thanks

Link to comment
Share on other sites

Oh, if you don't use Sprites, you can't use Groups either.

Array still has a few useful methods, like forEach and map.

Utility libraries like underscore and lodash provide more helpers. Here is underscore (findWhere)

var current_player = _.findWhere(players, {name: 'Sally'});

But if you're often looking up players by name, you might just index them that way instead:

game.players = {
  Sally: { color: 'green', score: 0 },
  Ana: { color: 'blue', score: 0 },
  // […]
};

In that case you'd probably want to add a utility library, since Object has few useful iterators built in.

Nonetheless, if you're familiar with the Group methods, there's really no harm in using them instead (and don't worry about the invisible sprites). Or is there some sprite you could associate with each player? Game markers?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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