Jump to content

Help with understanding z-order


bluedot
 Share

Recommended Posts

Hi,

 

I'm not particular clear on how to change the render order for Phaser. As I understand it I can create a group and then call sort on it as per the Phaser Sort example. That example only shows how to do it for the group of sprites, can I also add bitmap images to it ? and change set the sort order for individual objects ?

Do they all have to be in the same group ?

 

What I'm after is a pseudo 3-D effect of a bunch of sprites passing between 2 image objects. New sprites will be added and some will be removed during runtime, so the z value of the sprites should be changed as needed.

 

Thanks.

 

 

Link to comment
Share on other sites

The sprites are rendered by default in the order that they're added to the Group (the World being just another Group for all intents and purposes). Each group manages the display order of its direct children only - and any groups within groups will manage their display order separately and within the order of their parents. You can use Group methods like moveUp and moveDown to move children individually, addAt to place an object at a particular position and swap to switch positions of two children. Modifying the z property itself does not alter the depth of the object unless you subsequently call sort, which by default will use this value to determine the order of the children.

 

If you've ever used Flash, Phaser's scene graph is pretty much the same. Thus tutorials relating to scene management in Flash would also be good primers for working with Phaser or pixi.

 

Creative use of groups will help you create fixed 'layers', so you could create 3 groups in your case - a background, midground and foreground group, background with your 'behind' sprite, foreground with your 'in front' sprite and then the midground containing your sprites to pass between. This way you don't need to think about managing z-order as each group will manage its order internally, but in the overall scene everything will keep its order.

Link to comment
Share on other sites

Hi,

 

Unfortunately I've never used Flash, has been a C/C++ programmer for 90% of my working life and this is my 1st stab at a real HTML5+Javascript project.

 

So, what I should do is create 3 groups to add to the game object ? 1st is the background images, 2nd the sprites and 3 the foreground images, they will then render in that order ?

 

Just saw the 2nd part of your post.

 

Cheers.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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