L4 HW Beginner inhibitor
L4 HW Beginner inhibitor
Hi everyone, could you say more than the inhibitor. I seem to be missing something here. If a key is pressed and the inhibitor is defaulted to false the recticle slows down, but if it set to true nothing happens. What makes the inhibitor change to true? I seem to be hung up on this before I can move on.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: L4 HW Beginner inhibitor
When you press a key on the keyboard, it will usually last a few frames, so the idea is to inhibit that press on subsequent frames until you release the key that triggered the inhibitor.
Do something:
key_is_pressed | inhibit_key
--------------------------------------
true | false -> key is pressed for first time, handle pressed events
false | true -> key is released after press, handle release events
true | true -> key is still pressed from previous frame, just ignore
false | false -> key hasn't been pressed yet or has already been released and handled
Code: Select all
if( a_is_pressed )
{
if( ihibit_a == false )
{
// If we enter here, it means we haven't pressed the 'A' key yet
inhibit_a = true; // Now on the next couple of frames,
// ...do something when 'A' is pressed
}
}
else // if 'a_is_pressed == false
{
if( inhibit_a == true )
{
// 'A' has been released, so we can set 'inhibit_a' to false
// to allow a follow up press
inhibit_a = false;
}
}
key_is_pressed | inhibit_key
--------------------------------------
true | false -> key is pressed for first time, handle pressed events
false | true -> key is released after press, handle release events
true | true -> key is still pressed from previous frame, just ignore
false | false -> key hasn't been pressed yet or has already been released and handled
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: L4 HW Beginner inhibitor
ok got it. Thanks again for clearing it up for me.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: L4 HW Beginner inhibitor
You're welcome.
I am never really sure if I'm giving to much or too little information. I usually go overboard.
I am never really sure if I'm giving to much or too little information. I usually go overboard.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com