【问题标题】:Waiting in GameMaker: Studio在 GameMaker: Studio 中等待
【发布时间】:2016-05-27 16:56:14
【问题描述】:

我在 GML 中编写了一个脚本,该脚本应该在执行脚本之前等待几秒钟,但我尝试了它,但它不起作用。有人可以帮忙吗?而且我不想使用等待/睡眠功能,因为这会延迟房间里的一切。这是我的脚本。

//Rename this script according to what you want to wait for
//Here is how many seconds we want to wait.
var seconds = 0;
//We will multiply the amount of seconds by the room speed, and store it in a variable
var waittime = seconds * room_speed;
//Then, we will define a script for later
var script = "Your Script here";
//Then, we will add a question, and it will ask if the room speed is the same as the wait time
if (room_speed == waittime or room_speed > waittime) {
    //Then, if the amount of room speed is the same as the wait time, then execute the script
    script_execute(script);
}
else {
    //But if the amount of seconds is not equal, or greater than the wait time, then just add the fps to the wait time-
    waittime += fps;
}

【问题讨论】:

    标签: wait gml


    【解决方案1】:

    据我所知,GameMaker: Studio 中的睡眠功能已被移除。您可以使用闹钟制作自己的计时器脚本:

    在您的触发/暂停脚本中:

    instance_deactivate_all(true);
    alarm[0] = 60 //Your time in frames. If your room_speed is 60, this will be one second.
    

    然后在警报 0 事件中,您可以执行以下操作:

    instance_reactivate_all();
    

    虽然这将停止渲染您当前在屏幕上可能拥有的任何对象。 你的另一个赌注是创建一个global.timer = 60 并停止每个对象if(global.timer > 0) 的步骤事件,然后让类似director 对象的东西运行if(global.timer > 0) global.timer--;

    遗憾的是,不再有简单的方法可以做到这一点,但希望这两种方法就足够了。

    【讨论】:

    • 好的,但我想知道我的脚本是否可以工作。我只想等待 1 个对象,而不是所有对象。我最好的选择是使用另一个,我可以添加一个秒变量,然后将它乘以房间速度来创建全局计时器。然后我可以使用第二个脚本,并对其进行修改以制作淡入淡出的动画。
    • 在这种情况下,您可以有选择地将 if 语句放在要暂停的对象中。任何不检查全局计时器的对象将继续正常执行。
    猜你喜欢
    • 1970-01-01
    • 2022-08-08
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多