Jump to content

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


Recommended Posts

Hello, everybody.


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


here is the initialization:



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


initDrag: function(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);



Here is the drag events:

startDrag: function(currentElement) {

//some code


//some code

stopDrag: function(currentElement) { 

//some code

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)



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


  • Recently Browsing   0 members

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