我试图使它,当你点击它会显示0.25秒不同的cursor_sprite
。我目前需要一些方法来添加延迟到这个。下面是我到目前为止的代码:
创建事件:
/// @description Set cursor
cursor_sprite = spr_cursor;
In step event:
/// @description If click change cursor
if mouse_check_button_pressed(mb_left)
{
cursor_sprite = spr_cursor2;
// I want to add the delay here.
}
您可以使用内置的警报,但是当它与父对象嵌套时,我不太喜欢这些。
因此,我将这样做,而不是警报:
创建事件:
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
设置定时器
如果计时器达到零,它将在之后执行给定的动作。
虽然提醒它在步骤事件中,所以一旦计时器达到零,如果之前没有其他条件,它将始终到达else
语句。通常我使用else语句来改变条件,这样它就不会多次到达计时器代码。
@Steven:到目前为止,这是有用的,但我认为你混淆了timer
和timermax
的起始值。如果timer
从开始计数,那么它显然不能从0开始。
此外,在预期的持续时间启动timer
完全避免了使用第二个变量(timermax
)的需要。
所以可以这样写:
创建事件:
cursor_sprite = spr_cursor;
timer = 0.25;
步骤事件:
if mouse_check_button_pressed(mb_left)
{
cursor_sprite = spr_cursor2;
timer = 0.25;
}
if (timer > 0)
{
timer -= 1/room_speed //decrease in seconds
}
else
{
cursor_sprite = spr_cursor;
}