Jump to content

How to disable group incrementing my z values?


Apoptyzm
 Share

Recommended Posts

Hi,

somehow i can't use my group as a layer (example: http://examples.phaser.io/_site/view_full.html?d=groups&f=group+as+layer.js&t=group%20as%20layer ).

 

Whenever i add a sprite to a group, it's z layer is changed by group to match sprite's index number in group.

 

Basicly this code :

GroupWithTemplate.prototype.createObject = function(){    if(this.GroupSize < this.MaximumObjAmount){        var obj = this.Builder.construct(this.object_original.objecttype);        LOGADD("GroupWithTemplate.prototype.createObject fresh z: "+obj.z);        LOGADD("this.group.z: "+this.group.z);        this.group.add(obj );        this.GroupSize++;        LOGADD("GroupWithTemplate.prototype.createObject ingroup z: "+obj.z);    }};

produces output like this:

GroupWithTemplate.prototype.createObject fresh z: 12debug.js:18 this.group.z: 12debug.js:18 GroupWithTemplate.prototype.createObject ingroup z: 1debug.js:18 GroupWithTemplate.prototype.createObject fresh z: 12debug.js:18 this.group.z: 12debug.js:18 GroupWithTemplate.prototype.createObject ingroup z: 2debug.js:18 GroupWithTemplate.prototype.createObject fresh z: 12debug.js:18 this.group.z: 12debug.js:18 GroupWithTemplate.prototype.createObject ingroup z: 3debug.js:18 GroupWithTemplate.prototype.createObject fresh z: 12debug.js:18 this.group.z: 12debug.js:18 GroupWithTemplate.prototype.createObject ingroup z: 4debug.js:18 GroupWithTemplate.prototype.createObject fresh z: 12debug.js:18 this.group.z: 12debug.js:18 GroupWithTemplate.prototype.createObject ingroup z: 5debug.js:18 GroupWithTemplate.prototype.createObject fresh z: 12debug.js:18 this.group.z: 12debug.js:18 GroupWithTemplate.prototype.createObject ingroup z: 6debug.js:18 GroupWithTemplate.prototype.createObject fresh z: 12debug.js:18 this.group.z: 12debug.js:18 GroupWithTemplate.prototype.createObject ingroup z: 7

I checked group sourcecode, and the method responsible is updateZ() but its called in places that i never use, like sort() or remove().

 

I would apreciate any sugestions.

Link to comment
Share on other sites

A z-depth value refers to the displayObject's z-value within it's group.

 

In the example, all the clouds created within the cloudLayer group each have their own z-depth values, so the game knows the order in which the clouds should be drawn. However, all clouds belong tot the cloudLayer group, which has its own z-depth value. Since the cloudLayer group has a z-value of 1, while the groundLayer has a z-value of 2, the cloudLayer (and all the clouds it contains) will be drawn before the groundLayer.

 

So the draw order is this (top to bottom):

 

cloudLayer group (z = 1)

- cloud sprite (z = 1)

cloud sprite (z = 2)

cloud sprite (z = 3)

groundLayer group (z = 2)

ground sprite (z = 1)

 

 

The updateZ() method is actually required, because two objects within the same group cannot have the same z-depth value (the game wouldn't know which one to put in front).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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