Detect touch on a focused touched object

Good day

I’m currently trying to do this:

I have 2 objects, One is static with a touch event, the other is hybrid with a touch event also

The plan is, hybrid object should be dragged on top of the static object. Also If I hover over static object I should detect a moved state on static object, same as ended or cancelled.

Right now I can’t figure out how can I solve this

Hybrid Object

-has return true

-has focus

Static Object

-has return true

Here is my code

For Static:

forHover = function(self,event) local phase = event.phase if phase == "began" then -- print("Test") elseif phase == "moved" then print("Static moved state detected") else if phase == "cancelled" then else --DO SOMETHING ON RELEASE end end return true end 

For Hybrid:

dragOfItem = function(self,event) local phase = event.phase if phase == "began" then display.getCurrentStage():setFocus( self ) self.isFocus = true elseif phase == "moved" then -- print(self.coordinates) self.x = event.x self.y = event.y print("HYBRID IS MOVING") else if phase == "cancelled" then else --DO SOMETHING ON RELEASE OF HYBRID end display.getCurrentStage():setFocus( nil ) self.isFocus = false end return true end

Again, Static Object should detect moved state even if hybrid object is above it.

Thanks in advance.

Hi @vonncc123,

By “static” and “hybrid” I assume you’re using physics (although the correct term is “dynamic”, not “hybrid”). If so, then you need to set up collision detection between these two objects, which I don’t see in your code.

If you’re not using physics, then you need to set up some kind of non-physics collision detection, of which there are various examples here in the forums and online.

Best regards,

Brent

I can do it normally.

The problem is the focus part. when I focus an touch event, everything that has a touch listener will be disregarded.

Hmmm… I don’t fully understand the issue, and how the touching relates to the physics… they’re really two separate things.

Brent

Nevermind though, Im starting to understand Non-Physics collision, thanks in the advice :slight_smile:

Hi @vonncc123,

By “static” and “hybrid” I assume you’re using physics (although the correct term is “dynamic”, not “hybrid”). If so, then you need to set up collision detection between these two objects, which I don’t see in your code.

If you’re not using physics, then you need to set up some kind of non-physics collision detection, of which there are various examples here in the forums and online.

Best regards,

Brent

I can do it normally.

The problem is the focus part. when I focus an touch event, everything that has a touch listener will be disregarded.

Hmmm… I don’t fully understand the issue, and how the touching relates to the physics… they’re really two separate things.

Brent

Nevermind though, Im starting to understand Non-Physics collision, thanks in the advice :slight_smile: