我使用鼠标拖动画一个三角形。 在绘制了许多不同的三角形之后,我想使用鼠标拖动将一些三角形移动到不同的位置,但是我不知道如何将三角形拖动到不同的位置。求助:=(
答案 0 :(得分:2)
这里有一些假代码来详细说明他在说什么:
on mouse down: for each triangle, in reverse order of their drawing if the pointer is within the triangle's area set the "dragging" state in a member variable add a reference to the triangle to a member variable record the mouse position in a member variable record the initial position of the triangle in a member variable break end if end for on mouse move: if currently in the "dragging" state move the triangle by the same amount the mouse has moved end if on mouse up: if currently in the "dragging" state move the triangle by the same amount as the mouse has moved exit the "dragging" state end if