Jump to content

How to set an element to the top in the group after dragging?


weratius
 Share

Recommended Posts

Hello, everybody.

 

How can I set an element to the top in the group after dragging?

 

here is the initialization:

 

The LAYERS:

this.layers = {
profileLayer: game.add.group(),
itemsLayer: game.add.group()
}

 

initDrag: function(currentElement) {

game.physics.arcade.enable(currentElement);
currentElement.inputEnabled = true;
currentElement.input.enableDrag(false, true); //THIS IS IMPRORTANT
currentElement.events.ondragStart.add(this.startDrag, this);
currentElement.events.ondragStop.add(this.stopDrag, this);
},

createSprite: function(x, y, elementName, layerType) {
var obj = game.add.sprite(x, y, elementName);
obj.fixedToCamera = true;
obj.anchor.set(0.5, 0.5);
this.initDrag(obj);

this.layers.profileLayer.add(obj);
}

 

Here is the drag events:

startDrag: function(currentElement) {

//some code

this.layers.itemsLayer.bringToTop(currentElement);

//some code
},

stopDrag: function(currentElement) { 

//some code
currentElement.bringToTop();
}

I can't understand why the dragging element is still under other elements

 

I tried to use " currentElement.input.enableDrag(false, true); " and " bringToTop " on and after dragging

 

Thank in advance)

 

Link to comment
Share on other sites

I'm a bit confused because they already sort to top by default when you set this

currentElement.input.enableDrag(false, true)

http://phaser.io/sandbox/xSNZmouE/play

 

do you not want to bring it top top until drag is complete?

 

note ..bringToTop only sorts within their own group though

I don't understand that too, I consoled log the group which the dragging element belonged to and I saw that the element it the latest in the group.children array

 

I really can't get it at all

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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