When I drag the square shown in the code sample below, the square jumps around instead of aligning its position to the current mouse position.
posX = mouseX-posX+mouseX;
posY = mouseY-posY+mouseY;
are my attempt, to position the element at the position, where the user actually clicked the square rather then just drawing the square at the current mouse position such as,