Jump to content

Adding sprites


sjaka80
 Share

Recommended Posts

I'm new to Phaser and JavaScript, hence my apologies for a very basic question.

 

While going through example code, I saw two different variations of game.add.sprite() function:

 

1. game.add.sprite(100, 100, 'mushroom');

 

2. game.add.sprite(0, 0, 'wallH', 0, this.walls);

 

 

First piece of code is pretty straight forward to me. Adds a sprite (mushroom) at x,y position. i.e. game.add.sprite(x, y, object). I'm confused for the second piece. I get that the first 3 arguments are the same as the first example, but what are the two other arguments? this.walls I believe is the group the object belongs to, what is 0?

 

I've tried looking at Phaser's api documentation on the site, but being new, find it difficult to find relevant pages.

 

sjaka

Link to comment
Share on other sites

The relevant bit of the docs is: http://phaser.io/docs/2.4.4/Phaser.GameObjectFactory.html#sprite.

game.add.sprite(0, 0, 'wallH', 0, this.walls); 

is getting a texture from a spritesheet, so 'wallH' is the key for the spritesheet and the 4th argument (0) is the frame of that spritesheet. The last argument is telling Phaser to add this sprite directly to a group (this.walls) rather than at the top level or into the world group.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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