c# - 为技能使用添加冷却时间

标签 c# xna xna-4.0

所以我创建了一个打砖 block 桨,它基本上可以通过模拟摇杆左右移动。

if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X == -1.0f)
{
    // Player one has pressed the left thumbstick up.
    Position.X = Position.X - (5 + speedup1);
}


if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X == 1.0f)
{
    // Player one has pressed the left thumbstick up.
    Position.X = Position.X + (5 + speedup1);
}

speedup1 是一个设置为零的初始整数值,当 Player 按下右触发器时,它会将值设置为 5,从而提高桨的速度。

if (GamePad.GetState(PlayerIndex.One).Triggers.Right > 0)
{
    speedup1 = 5;
}

我想做的是在按下触发器后,speedup1 的值在设定的时间间隔后返回到 0,并且玩家无法再次更改它设置时间间隔。

请帮忙,

最佳答案

我不知道你的游戏是如何构建的,你需要为此发布更多代码,但一般来说:

Now imagine a cooldown for something in game. The player pressed "a", some cool action happened and although he may press "a" again, nothing will happen for the next 5 seconds. But the game still runs and does all the other things that may happen ingame. This is not a conventional timer. It's a variable, lets call it ActionCooldown, and once the player triggers the action, it's set to 5 seconds. Every time the world changes, the timePassed is subtracted from that number until it's zero. All the time, the game is running and handling input and rendering. But only once ActionCooldown hits zero, another press of "a" will trigger that action again.

引自here .

创建一个变量。将其设置为您的冷却时间值。从中减去时间,直到它达到零。冷却结束。

关于c# - 为技能使用添加冷却时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20064670/

相关文章:

c# - 如何设置 WebClient Content-Type Header?

c# - 如何对使用 FederatedAuthentication.SessionAuthenticationModule 的代码进行单元测试

xna - 在WP7 XNA 游戏中,如何在屏幕上创建一个半透明的矩形作为通知消息框?

c# - 两个数相除总是为零?

c# - XNA 平台共享的类库

c# - 必须是 unixtime 或 strtotime 可解析的日期/时间表示

c# - 创建进程 : error creating process handle

xna - 在哪里调用 SetRenderTarget?

visual-studio-2010 - 在 XNA 4.0 中以给定点周围的半径为地形模型着色

c# - FBX 模型无法在 XNA 4.0 中正确显示