I have a problem about how to continuously scale, for example, if I press ‘c’, it will continuously magnify then if I release ‘c’, it will stop the process.
I tried a while loop in KeyPressed function but the while loop just repeat ignoring the key release. How to do it?
Originally posted by mapds:
[b]I have a problem about how to continuously scale, for example, if I press ‘c’, it will continuously magnify then if I release ‘c’, it will stop the process.
I tried a while loop in KeyPressed function but the while loop just repeat ignoring the key release. How to do it?[/b]
the problem with that code is that it does not give a smooth result.
to achieve a smooth result you have to compute, every frame, the amount dt of time elapsed since the last frame. Then, you check whether the ‘c’ key is currently pressed. For this, either you use a cross-platform library like glfw, or you maintain an array of bools representing the keyboard, or you use a system-specific func like GetAsyncKeyState. Then you code the following:
if (c is pressed)
{ scale_factor += (SCALE_SPEED * dt);
}
(or maybe you’ll prefer an exponential formula like scale_factor *= (1 + SCALE_SPEED * dt); )
[This message has been edited by Morglum (edited 01-11-2003).]