Mouse Clicked function and storing variables

Hello! I am new to processing and was hoping someone can help.

I am drew an object and need it to glide from one mouse click location to another.

I used the mouseClicked function and stored the X and Y of when the mouse is clicked like this:

newX = mouseX
newY = mouseY

But is there is a way to store the next set of mouse clicks so I can calculate the distance between them for the glide? And of course when I click again after the initial two clicks, I need the second click variables to be stored with the third click variables.

Thanks for all your help. I have been trying to figure this out for 2 days now and my head might explode soon!!

1 Like

Here is a few things you might find helpful:

Here’s what I would try:

Create an arraylist and in setup add a random (or mouseX and mouseY) location to it.

Use the mouse clicked function add a location to the end of an arraylist.

Then in draw you have the object move towards the first thing in the arraylist. And If the object is within a certain distance (look into dist()) and the arraylist.size() is greater than 1 remove the first element in the arraylist.

Hope that make sense and is helpful.

1 Like