I have created a gui object with 2 boxes to act as buttons and one script. I would like this script to send a message to the player object depending on which button was pressed.
My question is how to know which button was pressed?
local jump = gui.get_node("jump")
local shoot = gui.get_node("shoot")
I get the reference to the buttons, but still can’t figure out which one received the input.
You can use gui.pick_node to see if mouse/touch/action.xy is within the rectangle of a specific gui node you are using for buttons. Then you check action events to see if button is released etc.
In touch triggers I have:
input: multi-touch
action: touch
function on_input(self, action_id, action)
local jump = gui.get_node("jump")
local shoot = gui.get_node("shoot")
if action_id == hash("touch") and action.pressed then
if gui.pick_node(jump, action.x, action.y) then
print("Jump Clicked")
elseif gui.pick_node(shoot, action.x, action.y) then
print("Shoot Clicked")
end
end
end
Nothing. But works if I replaced hash(“touch”) with hash(“mouse”) which is also mapped.
Multitouch I think can only be tested on devices but you can still detect mouse-button-1 as “touch” and on mobile it will also count as a touch input I am pretty sure.