scale event listener to smaller area than graphic it is attached to

Is it possible to scale the event listener so it doesn’t go edge to edge on the graphic it is attached to? For example I have a 320*240 image and I need to make the event listener smaller. (20px padding around the image would be ok)

The reason I am asking is I am trying to add a hint button in the middle of the page (Player loses points if they hit an incorrect image) but clicking the hint button always triggers the event listener (behind the hint button) while at the same time triggering the hint button (so that works at least), but it gives the person negative points because they hit the hint button AND the graphic behind the hint.

Even a link to an existing article would be ok. [import]uid: 132937 topic_id: 35221 reply_id: 335221[/import]

  • You can create a display.newRect, which is smaller than your image. Add touch event to this, and listener is what you want to do with the image
    Then you set two value:

local rect = display.newRect(0,0,w,h) rect:addEventListener("touch",listener) rect.isVisible = false --make it invisible rect.isHitTestable = true -- it can be touched althought it is invisible [import]uid: 9190 topic_id: 35221 reply_id: 140009[/import]

Excellent idea. Sometimes the most non-obvious answer is the easiest. Display a transparent rectangle on top with a smaller hit area. Perfect.

Thanks khanh.dq [import]uid: 132937 topic_id: 35221 reply_id: 140017[/import]

  • You can create a display.newRect, which is smaller than your image. Add touch event to this, and listener is what you want to do with the image
    Then you set two value:

local rect = display.newRect(0,0,w,h) rect:addEventListener("touch",listener) rect.isVisible = false --make it invisible rect.isHitTestable = true -- it can be touched althought it is invisible [import]uid: 9190 topic_id: 35221 reply_id: 140009[/import]

Excellent idea. Sometimes the most non-obvious answer is the easiest. Display a transparent rectangle on top with a smaller hit area. Perfect.

Thanks khanh.dq [import]uid: 132937 topic_id: 35221 reply_id: 140017[/import]