I would like to know how to use the joystick in python with something similar to the “tap” button in the logic bricks of joystick sensor.
For the keyboard, there is bge.logic.KX_INPUT_JUST_ACTIVATED which gives me the first input of the active key. But for the joystick, I’m using bge.logic.joysticks[0].activeButtons which gives me every frames where the button is pressed. Is it possible to have only the first frame of activation?
You will have to implement a feature like “just activated” “just released” yourself by storing the previous list of active buttons and comparing the new list to that.
#function that compares list of new ie currently active and old ie previously active keys and returns
#a list of containing both list of just activated and just released keys
def AnalyzeKeys(new, old):
just_activated = []
just_released = []
for key in new:
if not key in old:
just_activated.append(key)
for key in old:
if not key in new:
just_released.append(key)
return [just_activated, just_released]
Ok thank you!
I thought there was something in the API for that. Does it means that everything in logic brick is not always in the python API? It’s a pity but it seems not so hard to code in this case
Theoretically python offers a subset of logic brick features, but practically you can do more with python than logic bricks and especially more complex stuff. I believe “tap” is not a feature of the joystick sensor per se, rather it’s likely a feature of the sensor class which joystick sensor inherits from.
As you start making more and more complex games python and can use API well enough to replicate anything logic could ever offer, but same is not true other way around.