Closed lolbinarycat closed 4 years ago
Have you looked into reacting to key press bindings? It lets you immediately respond once a button has been pressed, and with vectors you can have an enter frame that continually applies a vector of force that is altered by the key press
One use is in the flappy bird example: https://github.com/oakmound/oak/blob/master/examples/flappy-bird/core.go#L123
f.Bind(func(int, interface{}) int {
f.Delta.ShiftY(-4)
return 0
}, key.Down+key.W)
Thanks! On the topic of bindings, is there a way to bind an event so it is triggered once when the entity comes onscreen? I know I could use event.Enter
and then unbind the event, but then it wouldn't happen again if it goes offscreen and back on.
Not exactly, there's the concept of phase collision objects in both the mouse and collision trees that could be used for this with a collision space that followed the viewport around, but there's no event triggered without setting one of those collision objects up.
The obvious solution is to use
oak.IsHeld
and check if the duration is less than 1 frame. The problem with that is that it can miss inputs if the game lags.One solution that should always work is storing the state of the key on the last check. Here's a simplified example:
There are a few problems with it:
Is there a better solution?