我想编写一个对象,当它按下鼠标左键时,它开始向 (x,y) 点移动,当它到达 (x,y) 点时它停止移动。我命令在鼠标左键单击时反对。对象以 75 px/s 的速度向 (x,y) 移动,但它不会在 (x,y) 点停止,它会继续移动。
问问题
921 次
1 回答
2
你可以使用这样的东西:
创建事件:
moving = false;
moving_speed = 4;
target_x = 0;
target_y = 0;
全局鼠标左按事件:
target_x = mouse_x;
target_y = mouse_y;
moving = true;
sprite_index = spr_walk; // Start animation
image_speed = 0.5; // Animation speed
步骤事件:
if moving and point_distance(x, y, target_x, target_y) > moving_speed
{
dir = point_direction(x, y, target_x, target_y);
x += lengthdir_x(moving_speed, dir);
y += lengthdir_y(moving_speed, dir);
}
else
{
moving = false;
x = target_x;
y = target_y;
image_speed = 0; // Stop animation
sprite_index = spr_stay;
}
于 2015-11-22T10:04:55.003 回答