Hi, I was wondering how you would make an actor follow the mouse when the mouse is clicked on the object, I know how to get the mouses X and Y coordinates, but no how to make the actor follow while the mouse is pressed on it
What exactly do you want?
- mouse pressed on actor → actor is set to mouse location as long as mouse is pressed/dragged = something like drag & drop
- mouse pressed on actor → actor is "selected" → mouse moves around, actor is set to mouse location until the next mouse click will unselect it = similar to above
- mouse pressed on actor → actor is "selected" → mouse click (right mouse button?) tells the actor where to move (strategy games)
- something else?
From your text, I would guess it is option number 1, but I am not really sure. If it is, you could check for the mouse click on the actor in the actor's class (act method) and if a click is detected, it passes itself to the world (something like a 'setSelected' method). Then the world sets the location of the selectedActor (if not null) to the mouse location if possible. When the mouse is released, you set the selectedActor back to null.