Ok thanks!
I just want to make sure I haven’t made any errors, cause
I’m currently making a game, and I’m using very similar code.
Anyone is free to use the code if needed!
Wick_movementExample.wick (166.8 KB)
Ok thanks!
I just want to make sure I haven’t made any errors, cause
I’m currently making a game, and I’m using very similar code.
Anyone is free to use the code if needed!
Wick_movementExample.wick (166.8 KB)
I forgot to mention that, oops. :’)
So this actually lead me to discover something very interesting! I don’t the exact intricacies of this, and maybe @Luxapodular can chime in on this, but it seems that if(key === “key”) works differently than if(isKeyDown(“key”)
I have a project here with one circle that moves using the first method, and then another that moves using the second method. Notice that the first circle can go diagonally and the second circle cannot. The second circle also does get the speed boost.
InputMethodDifferences.wick (2.3 KB)
Edit: this project is for the alpha editor!
Interesting differences here between how the same code behaves in the legacy editor and in the alpha!
Nice looking project by the way, @colorsCrimsonTears !
It took me a while to test your code cause that was actually my first time
using the alpha. Alphas a bit more confusing imo.
The movement ran quite nicely.
I guess the way you write the code is a matter of tastes? I hope the
TC can use one of these.
And thank you!
Hey @GoodL,
@zrispo and I took a look at your project. It seems that the problem in the isKeyDown
example, is that you were using else if
statements, even though this works with the key==="key"
style and here’s why.
Event and Key Rules
The Keydown event will run once for every key that is currently pressed down, per tick.
isKeyDown() will return true if the key passed in is any one of the keys currently held down.
Where we run into problems
So, in your if
/ else if
block for the isKeyDown
, what’s happening is the first key listed in your code is taking precedence over all other keys. Multiple conditional checks are true each time!
However in the key === 'key'
demo, only one of the conditionals is true each time Keydown
is run, because key
is changed for each one of them…
So, my recommendation is to use
if (key === 'up') {
// Do Something
} else if (key === 'down') {
// Do Something Else
}
isKeyDown
is very useful when you’re attempting to check if a key is down in another type of function, like update or load, but actually can cause issues when placed inside the Keydown
event without knowing this difference.
Let me know if this was a good writeup / if I can clarify anything else.
Brilliant, thanks a bunch for looking into that and explaining it! Good stuff to know, I appreciate it