How to create a textbox blinker?

Started by
4 comments, last by FMDGames 18 years, 1 month ago
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? :)
Advertisement
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.
would this not flash differently depending on the fps?
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.
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;}

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

It works great. Thanks for your help!

This topic is closed to new replies.

Advertisement