I have been trying to use the queryAABB method to create a fixture on the touch/mouse coordinate to detect which body (randomly spawning, active and moving, 32x32) has been touched.
local function onTouchesBegin(event)
local x = event.touch.x
local y = event.touch.y
local fixtures = thisLevel.B2_Worlds[1]:queryAABB(x - 0.00005, y - 0.00005, x + 0.00005, y + 0.00005)
if #fixtures > 0 then
local body = fixtures[1]:getBody()
print("Begins: Touched something!")
end
end
However, this doesn't seem to yield consistent results. Sometimes I get #fixtures>0, most times I don't. Changing queryAABB size doesn't really affect the outcome. I want to avoid Sprite hit-detection.
Any ideas?
Comments
for those who need to know, don't forget to use stage:globalToLocal(x,y) on the returned event's coordinates.
I am using TiledAsWorldEditor class to manage the world. Maybe thats why.