Touch area selection

Can’t fix a bug.

I use “Defold Input” by britzl and “Gooey” by britzl.
The picture shows the screen of my game. If you click on the screen, a laser is shot and a sound is played, but if you press the pause button, then the sound of the shot occurs and the game is paused. I need to limit the touch area for the shot, but I can’t figure out how to do it.

You need to define dead zones where you can’t shoot lasers / you ignore shoot input if action happens there. There are various ways to detect dead zones. You could use collision objects. You could check if the action is higher than a certain y value and ignore it. You could use a function like below to see if the action x,y is within a certain rectangle at the top of the screen.

local function point_within_rectangle_centroid(point_x, point_y, rectangle_x, rectangle_y, rectangle_width, rectangle_height)
	local width_half = rectangle_width / 2
	local height_half = rectangle_height / 2
	if point_x >= (rectangle_x - width_half) and point_x <= (rectangle_x + width_half) then
		if point_y >= (rectangle_y - height_half) and point_y <= (rectangle_y + height_half) then
			return true
		end
	end
	return false
end
2 Likes

Thanks for the tip. The solution turned out to be super simple, as I just did not guess right away. =)
This is how I did it.

function on_input(self, action_id, action)
	if action.y < 500 then
		local g = self.gesture.on_input(action_id, action)
		if g then
			msg.post(".", "on_gesture", g)
		end
	end
end
3 Likes