Jump to content

Moving child between groups on drag


Recommended Posts

My problem is the same as the post at http://www.html5gamedevs.com/topic/2660-bring-sprite-to-front-over-all-other-groups/ , which states...



I'm making a new game where I have several groups of sprites.


One of those groups should be at the bottom, behind ever other sprite group. Yet, if any of these sprites is being dragged, I want to bring it to top, not only over other sprites in its same group, but also over every other sprite on every sprite group in the game.


I have checked both "bring to front" examples and maybe I don't get it right, but that doesn't seem to be an option.

I've also thought about modifying the renderOrderID of the sprite, but I'm not sure that's something I should do manually.


Any ideas? Thanks in advance  :)


The solution presented was



You could use a group on top reserved for sprites being dragged.

When the drag starts, add the sprite to this group, which will remove it from the group it was in, and when the drag stops, re-add it to the group it came from.


This solution is exactly what I am looking for, however, when I try to implement it, the second drag (which moves the child from a small parent onto a group above) makes the child fly to a weird place. I've tried putting it back under the mouse by explicitly using position.x/.y, but that seems to fail. Any ideas on how I can correct this?

Link to comment
Share on other sites

  • 1 month later...

Just an update, it looks like I was able to fix this by changing my order of operations. I'm currently doing something like this (item is what I'm dragging - it's already at position 0,0 of its parent when I drag it):

onDragStart() {  var temp = game.make.sprite(item.world.x, item.world.y);  temp.addChild(item);}onDragStop() {  //transfer item to another parent  temp.destroy();}
Link to comment
Share on other sites


  • Recently Browsing   0 members

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