Sign in to follow this  
FMDGames

How to create a textbox blinker?

Recommended Posts

FMDGames    134
I've created a textbox in D3D, and i want to implement a blinker. I need it to blink at a const interval eg once every .5 sec but remember its in the render loop, so it cant be sleep() etc. Suggestions? :)

Share this post


Link to post
Share on other sites
greenwire    145
assuming you have a float representing the elapsed time since the last frame, i'd do this:

timer += elapsedtime * somevalue;
if (timer > 0.5f) draw blinker;
if (timer > 1.0f) timer = 0;


hth
n.

Share this post


Link to post
Share on other sites
greenwire    145
no. it's the same technique you use to get the camera to move at a fixed speed or make a car move at a fixed speed.
i use it with my blinker (i think theyre called carats) and it runs at approx. 4 blinks per second regardless of frame rate.

Share this post


Link to post
Share on other sites
Endurion    5411
Tiny nitpick: You've got a small error that might get visible if you show more than one on the screen:

if (timer > 1.0f) timer = 0;

This discards the "overflow", change it to


if ( timer > 1.0f )
{
timer -= 1.0f;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this