weratius Posted October 17, 2015 Share Posted October 17, 2015 Hello, everybody. I have such a problem: I have two layers:this.layers = { profileLayer: game.add.group(), itemsLayer: game.add.group()};After clicking a close button I need to destroy the "profileLayer" and hide "itemsLayer"closeProfile: function() { closeButton.kill(); myObject.layers.profileLayer.destroy(); //these elements had been added to the "itemsLayer" before for(var element in itemsObject.items) { itemsObject.items[element].cell.visible = false; if(itemsObject.items[element].item != null) { itemsObject.items[element].item.visible = false; } }} Then I need to init them again (I closed profile and I was trying to open it again), so: if(!this.itemsAlreadyHasBeenLoadedOnce) { myObject.layers = { profileLayer: game.add.group(), itemsLayer: game.add.group() } } else { myObject.layers.profileLayer = game.add.group(); }But the "profileLayer" is set higher than itemsLayer (z-index) How can I make itemsLayer to be always the highest layer? Thank you in advance guys. Good luck Link to comment Share on other sites More sharing options...
AzraelTycka Posted October 17, 2015 Share Posted October 17, 2015 Hello, did you try bringToTop? weratius 1 Link to comment Share on other sites More sharing options...
weratius Posted October 17, 2015 Author Share Posted October 17, 2015 Hello, did you try bringToTop? something like this ? here is an error:Uncaught TypeError: Cannot read property 'parent' of undefinedif(!this.itemsAlreadyHasBeenLoadedOnce) { myObject.layers = { profileLayer: game.add.group(), itemsLayer: game.add.group() } } else { myObject.layers.profileLayer = game.add.group(); myObject.layers.itemsLayer.bringToTop(); } Link to comment Share on other sites More sharing options...
AzraelTycka Posted October 17, 2015 Share Posted October 17, 2015 Ehm, which line is your error from, it says you are doing some operation on undefined object, so check where it is and console.log it to see what your object looks like. weratius 1 Link to comment Share on other sites More sharing options...
weratius Posted October 17, 2015 Author Share Posted October 17, 2015 Ehm, which line is your error from, it says you are doing some operation on undefined object, so check where it is and console.log it to see what your object looks like.It is on the bringToTop line Link to comment Share on other sites More sharing options...
AzraelTycka Posted October 17, 2015 Share Posted October 17, 2015 Yeah but what your object looks like? Console tells you you are calling bringToTop on undefined object, so if it's undefined then define it. Link to comment Share on other sites More sharing options...
Recommended Posts