Jump to content

REALLY struggling with layers


grumpygamer
 Share

Recommended Posts

Hi, I'm using phaser and it works well for every aspect up to now EXCEPT layers.

No matter what I can't fathom how they work.

 

I add elements to them and then sort them, BUT based on WHERE I add them, the sort has a different effect.

 

Anyhow here's my problem today:

 

I have HANGAR which is a state, so I delcare it with some layers:

hangar = function(game){        this.layerBg          = game.add.group();        this.layerShips       = game.add.group();}

I then extend the prototype adding a create function that adds to the layers:

hangar.prototype = {    init: function(selectedItem){       ...    },    preload: function(){       ...    },    create: function(){        this.createBackground();    }}

I then add the method separately:

hangar.prototype.createBackground = function() {        layerBg    = this.layerBg;	bg_start = this.game.add.sprite( hangarbg_start_x, this.game.world.centerY, 'hangarbg_start');        bg_start.anchor.setTo(0, 0.5);        bg_start.z = 1;        layerBg.add(bg_start);}

... as you can see, simple stuff.

 

Do you think it shows up? NO WAY.

 

- If I look inside the layer object I can see it in there via console.

- If I don't add it to the group I can see it correctly.

 

These layers are really in need of a WIKI-sort of explanation.

 

Can someone please help?

Thanks!

Link to comment
Share on other sites

You should create your groups inside of the 'create' method, not in the constructor - at that point in time it's probably not even the active state, so the groups are likely cleared from the display list by the time the state is active.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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