# 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 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 on other sites
FMDGames    134
would this not flash differently depending on the fps?

##### 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 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 on other sites
FMDGames    134
It works great. Thanks for your help!