Jump to content

Drawing a Sprite


Nightmare Games
 Share

Recommended Posts

I've just begun working with Phaser yesterday and I'm a bit confused about how to get my sprites drawn on the screen.

 

I've noticed Phaser seems to draw images automatically, based on the order they're loaded in.  For the game I'm working on, I'm not sure how to proceed using that method.  None of the examples I've looked at have a traditional "draw game" or "render" function that draws everything each step, and I haven't been able to find information on any type of "draw sprite" function that would let me take control of the drawing myself.  Does such a function exist?

Link to comment
Share on other sites

When you add a Sprite to the World (which is what game.add.sprite does automatically) it adds it to the display list. If you create a sprite outside of the factory, so just sprite = new Phaser.Sprite, then it won't render until it's added to the World (or a child that is already present in the World).

 

But you never have to explicitly say 'render this sprite', which is why they don't have render methods. As soon as they are on the display list, they render until you either remove them or set their visible state to false.

Link to comment
Share on other sites

Suggestion for version 1.2

bringToTop() is a Sprite class method

Brings the Sprite to the top of the display list it is a child of. Sprites that are members of a Phaser.Group are only bought to the top of that Group, not the entire display list.

it's a useful method but it may be sometimes too limited.

Maybe would it be appreciable to have a direct access to a DisplayList class with some methods to manage the render order (if it doesn't already exists, I couldn't find it) ?

Link to comment
Share on other sites

Just in case anyone needs this, in current build (1.1.4) I used the Group._container property to access the PIXI.DisplayObjectContainer and its swapChildren(child1, child2) method in order to sort groups in another group (or world). 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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