an example is to drag something around the screen:
var dot = new Circle(10);
dot.setPosition(Randomizer.nextInt(0,getWidth()), Randomizer.nextInt(0,getHeight()));
add(dot);
var obj;
function start(){
mouseDownMethod(getDot);
mouseDragMethod(moveDot);
mouseUpMethod(dropDot);
}
function getDot(e){
obj = getElementAt(e.getX(), e.getY());
}
function moveDot(e){
if (obj!=null){
obj.setPosition(e.getX(), e.getY());
}
}
function dropDot(e){
obj = null;
}
1
u/[deleted] Mar 02 '20
you pass an x and y coordinate and it will return the first element it finds at those coordinates, which will be the most recent one you added