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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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