Jump to content

How to add objects on Layer?


PRSoluções
 Share

Recommended Posts

Hi,

1 - On my multiplayer game i need put something in different layers:

L1 = tiled map floor

L2 = tiled map floor fixed objects 

L3 = under players effect

L4 = game objects

L5 = game bullets and bombs

L6 = players floor

L7 = over players floor

L8 = tiled map - third layer with roof

 

2 - Another problem is that i want that the current player always see their player in front of all other players, like a zindex. Have it on phaser?

 

Thanks.

 

Link to comment
Share on other sites

6 hours ago, VitaZheltyakov said:

The Phaser has no concept of z-index. Allocated to each layer of a single group and distribute the elements within the group.

This.

 

You may want to check this example:

http://phaser.io/examples/v2/groups/group-as-layer

 

Also, to have a deeper look at Phaser's groups check this:

http://phaser.io/docs/2.4.4/Phaser.Group.html

 

Cheers! :)

Link to comment
Share on other sites

Imagine each group as a piece of paper. Each time you call "game.add.group" you are adding another sheet of paper on to the stack. That means that the last group you add is the top of the stack. If the player is looking down at the stack, that means that the last group you added is the "first" one they see, the one on top.

You can then add sprites and images and whatever else into different parts of this stack depending on what they need to be in front of or behind.

Here's the list of groups that I'm using in The Big Game:

// This is how everything stays ordered so niiiiice.
const GROUPS = [
  'sky',
  'stars',
  'background',
  'emitters',
  'spikes',
  'obstacles',
  'switches',
  'kiosks',
  'objects',
  'player',
  // TODO:0 Consider making "projectiles" group?
  'enemies',
  'foreground',
  'foregroundObjects',
  'fog',
  'lighting',
  'flares',
  'glowing',
  'dialog',
  'menu',
  'screenFlash'
];

I store all these groups for later so I can, anywhere in the code, say "game.groups.foreground.add" or "game.groups.spikes.add" and it'll go in the right place.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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