我们如何通过动画在游戏制作者中改变对象的位置?

时间:2015-11-21 14:57:30

标签: animation move game-maker gml

我想编写一个对象,当按下它的鼠标左键时,它开始向(x,y)点移动,当它到达(x,y)点时,它停止移动。 当我用鼠标左键点击它时,我命令对象。物体以75 px / s的速度向(x,y)方向移动,但它不会停在(x,y)点,它继续前进。

1 个答案:

答案 0 :(得分:2)

您可以使用以下内容:

创建活动:

moving = false;
moving_speed = 4;

target_x = 0;
target_y = 0;

Global Mouse Left Pressed Event:

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;
}