2.2.2 Gradual Changes

The method Kb.bp() can be used for sudden changes. For example when you open a window, add an object, show a menu or close the application. Like this:

 
if(Kb.bp(KB_F1)) CreateObject();  

Imagine you would use the method Kb.b() instead. As long as the F1 key is held down, a new object will be created. On a fast computer, this would be about 60 times a second. And even when you’re really fast and release the key almost instantly, you will probably create more than one object.

Still, this is a usable method, but only when you need gradual changes. Like when you move a dot to the right as long as a key is held down:

 
if(Kb.b(KB_RIGHT)) point.x += 0.01;  

Every frame, the value of x will increase a little bit. The dot will gradually move to the right.

Exercise
Adapt your last exercise to use the Kb.b() method. The dot will now move very fast, so you might want to decrease the added value.