Sign in to follow this  
Sakuk3

Dragging Buttons

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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). :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.