Events related to snapshot

Hello everybody

While using the snapshot library I’ve encountered a problem. If you want to add an event to a children (like a tap event) of the snapshot, you won’t be able to call the function event by “tapping” the children.

The thing is that I need to use the snapshot while having some images (children) which have tap events on them. What should I do? There is a function that allow me to do that?

P.S. I’m sorry, I’m not a native english speaker, I might have done some errors

This is an example:

local W=display.contentWidth

local H=display.contentHeight

local snap = display.newSnapshot( 300, 300 )

snap.x=W*0.5

snap.y=H*0.5

local space = display.newImageRect(“images/space.jpg”,300, 300)

snap.group:insert(space)

function foo(event)

   print("the function has been called correctly ")

end

local blueRect = display.newImageRect(“images/blueRect.png”,30,30)

blueRect:addEventListener(“tap”,foo) --I can’t call this event by clicking on it.

snap.group:insert(blueRect)

Hi Francesco,

When you use a snapshot, and insert children inside, they become part of the overall snapshot and cannot have individual tap listeners on them. However, maybe you can create another display object (isVisible=false, but also .isHitTestable=true) at the same location as the child (when you add it to the snapshot), and then you add a tap listener to that object. So, basically, the new object is in the same location as the child within the snapshot, and it detects tap events.

Hope this helps,

Brent

Thank you Brent, this actually helped me :smiley:

Hi Francesco,

When you use a snapshot, and insert children inside, they become part of the overall snapshot and cannot have individual tap listeners on them. However, maybe you can create another display object (isVisible=false, but also .isHitTestable=true) at the same location as the child (when you add it to the snapshot), and then you add a tap listener to that object. So, basically, the new object is in the same location as the child within the snapshot, and it detects tap events.

Hope this helps,

Brent

Thank you Brent, this actually helped me :smiley: