Jump to content
  • Advertisement
Sign in to follow this  
cutenoob

Hello,,I encounter a problem,,

This topic is 4436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,, It's my first time post here..well,my English is not very well,however, I'll try to explain it clear... The problem is the UI system..actually is the weapon/skill button,I must set a cooldown effect on which the button was pressed.(like WOW ) But I have no idea to do that,now I have to post this thread here , wish someone did it before and give me some suggestions... thanks...

Share this post


Link to post
Share on other sites
Advertisement
The most accurate way to time things is using the high performance counter if your hardware has one. This is controlled and queried using QueryPerformanceFrequency() and QueryPerformanceCounter() which are part of <windows.h>. For example your code might look something like:


struct Button
{
long m_frequency;
long m_startCount;
bool m_locked;
float m_coolDown;

void Initialise();
bool Push();
void Update();
}

void Button::Initialise()
{
QueryPerformanceFrequency(&m_frequency);
m_locked = false;
m_coolDown = 1.0f; // 1 second count before re-activation allowed
}

bool Button::Push()
{
if(!m_locked)
{
QueryPerformanceCounter(&m_startCount);
m_locked = true;
return true;
}
return false;
}

void Button::Update()
{
if(m_locked)
{
long currentCount;
QueryPerformanceCounter(¤tCount);

float timeElapsed = (float)(currentCount - startCount)/(float)m_frequency;
if(timeElapsed >= m_coolDown)
{
m_locked = false;
}
}
}


Note that I just made that up to give you an idea, there's no error checking or anything like that so I wouldn't use it directly. Also not all hardware has a high performance counter. In this case QueryPerformanceFrequency() will give you a frequence of zero. If this happens you can always fall back on using timeGetTime() which returns the system time in milliseconds.

Share this post


Link to post
Share on other sites
I pretty much agree, except to make one small point. You wouldn't want seperate timer code in every little thing that uses timed effects, but would probably have a game timer that your button would check against. (Unless QPC is really low overhead and doesn't need any error checking, I guess. But it's probably still a good idea to abstract it out in case a better timing model comes out or something.)

Share this post


Link to post
Share on other sites
Quote:
Original post by Bob Janova
I pretty much agree, except to make one small point. You wouldn't want seperate timer code in every little thing that uses timed effects, but would probably have a game timer that your button would check against. (Unless QPC is really low overhead and doesn't need any error checking, I guess. But it's probably still a good idea to abstract it out in case a better timing model comes out or something.)


Sound advice. In fact the way I do it is I've embedded my clock into the windows messaging loop and pass the time elapsed each frame as a parameter into the main game loop. This has several advantages. For a start the high performance counter doesn't have to be queried by each object that requires timing thus saving some cycles just like Bob says. It also ensures that every game object observes the same passage of time each frame. If each object is responsible for its own clock then they can start to diverge due to differing execution lengths of code between objects. Lastly when the clock is placed here it can also be used to fix your frame rate to prevent stuttering graphics.

Share this post


Link to post
Share on other sites
Thanks ....but that's not the answers....

all I want to know just the effect..not compute the cooldownh time,,just want to know how can i do to make the weapon/magic button rounded itself ? should I make a lots of alpha image and definition there slope/(alpha area) and render them at right moment?

very thanks those guy,,it make me more clear about my poor English,, LOL

Share this post


Link to post
Share on other sites
I'd just render one alpha image (the button) with a different colour value applied to it, and then interpolate the colour using code similar to Motorherp's (although I'd probably avoid the QueryPerformance* routines as I've heard there's multi-threading issues with them).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!