Virtual buttons

Hello guys, im glad here with you and sorry about my english, well i’ve read something about virtual buttons and i want to include them in my game, i have already the left and right movement for my player, but with the jump i have problem… if the player press the jump button i want he jumps, i know how do it with action.pressed but in my case is with message and i dont know how do it, i want he reach a position in ‘y’ when he is pressing the button, im sending a message from button.script to my player.script… any suggest?


— button.gui_script —

function on_input(self, action_id, action)

if action_id == hash("touch") then

	if action.pressed then
		local buttonThree = gui.get_node("JumpButton")
		if gui.pick_node(buttonThree, action.x, action.y) then
			msg.post("ball#player", "jump")
		end
	end

	local button = gui.get_node("RightButton")
	local buttonTwo = gui.get_node("LeftButton")
	if gui.pick_node(button, action.x, action.y) then
		msg.post("ball#player", "der")
	elseif gui.pick_node(buttonTwo, action.x, action.y) then
		msg.post("ball#player", "izq")
	end

end
end

— player.gui_script —

function on_message(self, message_id, message, sender)

if message_id == hash("der") then 
	value.x = value.x + 1
	go.set_position(value)
elseif message_id == hash("izq") then
	value.x = value.x - 1
	go.set_position(value)
elseif message_id == hash("jump") then
	if self.saltando then
		
		self.saltando = false

end
end
end

1 Like