Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Dragging Buttons


Sakuk3
 Share

Recommended Posts

It is actually pretty complicated to add a button to a draggable sprite. My current approach is:

- check the distance of the drag in onDrag signal of the draggable sprite

- if the drag is not too far, meaning it is a tap:

    + cancel the drag if needed (reset position)

    + dispatch the onClick signal of the button.

However, if there are multiple buttons or sprite inside the draggable sprite, and/or the button doesn't cover the entire sprite, you would need to see if the tap is on the button or which button it is on by:

    + set the priorityID of all the buttons to something big (99?)

    + use the processInteractiveObjects method of Phaser.Pointer to find the button

    + issues onClick signal of that button.

    + reset the priorityID of all the buttons to 0

 

I bet it's because the sprite isn't set "inputEnabled = true;", but I'm just guessing. What if you didn't add the button to the sprite but set its x/y position in an update method to follow the sprite around? Is that a good workaround?

 

If the sprite isn't set inputEnable to true, it wouldn't be able to be dragged :) I think Sakuk3 wants to drag the sprite while dragging the button too but also can click on the button (like I did with my games). :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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