Jump to content

Adding sprites and adding them to groups in the same line


evilwizard
 Share

Recommended Posts

I looked at the documentation on how to create a sprite

https://phaser.io/docs/2.6.2/Phaser.GameObjectFactory.html#sprite

It takes in the following parameters

  1. x
  2. y
  3. key
  4. frame
  5. group

It's very easy to add a sprite with just the first three parameters

car1 = this.game.add.sprite(800, 400, 'car');

But it fails when I try to add the car to a group

car1 = this.game.add.sprite(800, 400, 'car', objects);

If I went with the first declaration and then added

objects.add(car1)

it will then work

I need to use the second declaration because my codebase is becoming way too large, and I need fewer lines.

Not sure, why this is failing. Maybe an update killed this functionality?

Link to comment
Share on other sites

46 minutes ago, samme said:

You need to omit frame (4):


car1 = this.game.add.sprite(800, 400, 'car', null, objects);

 

I would like to thank you for your quick response.

Indeed, you must pass in something for all of the parameters, even if it's null. I got confused because the documentation said they were optional. Adding null to the frame parameter solves this issue.

Once again, thank you. This was very helpful for me

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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