换房间时 Game Maker 2 路径中断

Game Maker 2 path breaks when changing rooms

我正在 GMS 2 中制作游戏。作为游戏的一部分,我有一个沿着路径移动的对象,我希望它在我更换房间后继续沿着相同的路径移动。我注意到这不起作用 - 路径照常继续,但对象的 X 和 Y 坐标完全改变,完全没有任何原因 - 我在调试模式下尝试了这个,并且在某些时候它们只是改变了。仅当我在路径处于活动状态时更改房间时才会发生这种情况。这是路径创建代码:

if (mp_grid_path(my_grid, my_path, x, y, dest_x, dest_y, 1)) {
            path_start(path, ny_speed, path_action_stop, false);
        } else {
            show_debug_message("no path!!!");
        }

我发现解决这个问题的方法是在房间结束时保存路径,然后在房间开始时从同一点恢复它。 在房间尽头:

if(is_walking) { // only do this if the object is currently walking
path_end();
}

房间开始时:

if(is_walking) { // only do this if the player is currently walking
if (mp_grid_path(my_grid, my_path, x, y, dest_x, dest_y, 1)) {
    path_start(path, my_speed, path_action_stop, false);
} else {
    show_error("no path!!!", true); // if there is no path at this point, we have an error - because it existed before we changed the rooms, so it should exist now
}
}

希望这对以后遇到此问题的任何人有所帮助。