mousePressed versus mouseDragged - both needed. Right order?

edited January 2014 in Using Processing

Hello all,

I need to use mousePressed versus mouseDragged - both are needed.

What is the right order?

What I need:

  • I need to click an apple to change it to another fruit (I use mouseClicked).
  • But I also need to drag the apple.

So I use mousePressed and then set mouseHold to true

but how can I distinguish if it has been dragged or just clicked (in the function mouseReleased)?

Thank you all!

Greetings, Chrisir

Answers

  • Answer ✓

    Create a boolean variable called beingDragged and initialise it to false.

    In mouseDragged set it to true.

    In mouseReleased test it to see whether the mouse had been dragged. In any case set it to false before leaving the method to reset it.

  • edited January 2014

    Thanks, quark!

    I got confused because I used mouseClicked first which doesn't go together with mouseDragged...

    now my order is:

    • mousePressed (it occurs no matter if you click or drag and before releasing) - store index of apple
    • mouseDragged (set beingDragged to true)
    • mouseReleased (in mouseReleased check the boolean variable called beingDragged and do the appropriate thing: either change fruit (when false) or position (when true))

    don't use mouseClicked ...

    Also in draw() I say: When beingDragged show apple at mouse-position...

    Thanks a lot!

    Greetings, Chrisir

Sign In or Register to comment.