Computer Science Canada How to make KeyDown provide one output? |
| Author: | JakeTakeLake [ Mon Feb 25, 2013 7:03 pm ] | ||
| Post subject: | How to make KeyDown provide one output? | ||
What is it you are trying to achieve? In my game, I have a character controlled by keys. What I'm trying to do is make the KeyDown provide a single output, until it is released and pressed again. As opposed to providing multiple outputs for the duration that the key is pressed. Sorry if I didn't explain well. For example, I want the sprite to be changed to "punch" for one frame when the key 'd' is pressed. Instead, the sprite is being changed to "punch" for the time that the key is held down(multiple frames). What is the problem you are having? Implementing this. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using 4.1.1 |
|||
| Author: | Dreadnought [ Mon Feb 25, 2013 7:33 pm ] |
| Post subject: | Re: How to make KeyDown provide one output? |
Basically you want to check if the key was down the last time you called Input.KeyDown. How might you be able to keep track of the last state of the key? |
|
| Author: | evildaddy911 [ Tue Feb 26, 2013 11:24 am ] |
| Post subject: | Re: How to make KeyDown provide one output? |
what you need is 2 keys variables: - 2 variables: "current", "last" - initialize "last" - start loop - update "current" - check current(K)=true, last(K) = false - "last"="current" - end loop |
|
| Author: | JakeTakeLake [ Tue Feb 26, 2013 6:24 pm ] | ||
| Post subject: | RE:How to make KeyDown provide one output? | ||
here's what i did, but it doesn't work
|
|||
| Author: | Tony [ Tue Feb 26, 2013 7:37 pm ] | ||
| Post subject: | RE:How to make KeyDown provide one output? | ||
try adding
before every place where you are reading it. |
|||
| Author: | evildaddy911 [ Wed Feb 27, 2013 8:40 am ] |
| Post subject: | RE:How to make KeyDown provide one output? |
what i meant by "update 'current'" is by using Input.KeyDown(). also, what didn't work? did it crash or give the wrong output? if it crashed, why? (check the bottom of the window for error messages) |
|