如何创建一个定时器,做什么? [英] How to create a Timer that does something?

查看:205
本文介绍了如何创建一个定时器,做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的XNA C#,我想知道我怎么创建XNA C#,做几秒钟后,东西计时器。



我见过一个Flash教程,做什么,我需要,但我不知道该怎么做它在XNA C#



我试图用一个定时器,使在我的项目的一定期限内闪烁模式。因此,我需要知道我该如何启动定时器和怎么做定时器触发我的模型的闪烁。



感谢。


<在更新DIV CLASS =h2_lin>解决方案

做类似下面

 浮动elapsedTime =(浮动)gameTime.ElapsedGameTime.TotalSeconds; 



再有像



为秒变量

 浮动定时器= 5.0F; //五秒钟



然后更新

 计时器 -  = elapsedTime 

如果(定时器< = 0)
{
// Hanlde眨眼这里
定时器= 5.0F; //复位定时器
}


I'm quite new in XNA C# and I would like to know how do I create a timer in XNA C# that does something after few seconds.

I've seen a Flash tutorial that does what I need but I don't know how to do it in XNA C#

I'm trying to use a timer to make a blinking model in certain period of my project. Therefore, I need to know how do I start the timer and how does the timer toggle the blinking of my model.

Thanks.

解决方案

Do something like below in update

float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

then have a variable for seconds like

float timer = 5.0f; // Five seconds

then in update

timer -= elapsedTime

if(timer <= 0)
{
    // Hanlde the blink here
    timer = 5.0f; // Reset timer
} 

这篇关于如何创建一个定时器,做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆