【问题标题】:Delay time in GMS2GMS2 中的延迟时间
【发布时间】:2021-11-03 14:40:01
【问题描述】:
我正在尝试让它在您单击时显示不同的cursor_sprite 0.25 秒。我目前需要一些方法来增加延迟。到目前为止,这是我的代码:
在创建事件中:
/// @description Set cursor
cursor_sprite = spr_cursor;
步入事件:
/// @description If click change cursor
if mouse_check_button_pressed(mb_left)
{
cursor_sprite = spr_cursor2;
// I want to add the delay here.
}
【问题讨论】:
标签:
game-maker
gml
game-maker-studio-2
【解决方案1】:
您可以为此使用内置 Alarms,但是当它与父对象嵌套时,我不太喜欢这些。
所以我会这样做,而不是警报:
创建事件:
cursor_sprite = spr_cursor;
timer = 0;
timermax = 0.25;
我创建了 2 个变量:timer 将用于倒计时,timermax 用于重置时间。
步骤事件:
if (timer > 0)
{
timer -= 1/room_speed //decrease in seconds
}
else
{
cursor_sprite = spr_cursor;
}
if mouse_check_button_pressed(mb_left)
{
cursor_sprite = spr_cursor2;
timer = timermax;
}
对于每个计时器,我通过1/room_speed在Step Event中让它倒计时,这样,它会以实时秒为单位减少值。
然后可以通过timer = timermax设置定时器
如果计时器达到零,它会在之后执行给定的操作。
虽然提醒它在 Step Event 中,所以一旦计时器到达零,如果之前没有其他条件,它总是会到达 else 语句。通常我使用 else 语句来改变条件,所以它不会多次到达计时器代码。