Different Tap Functions Based on Location of Tap

I’m using the sample code slideview for my flashcard app. I want to be able to play a different sound depending on the location of the tap.

I’m currently checking if DragDistance is zero and if Touch.y < 246 play sound under the event.phase == “ended” function. But I’m getting weird bugs when I put the app on my iPhone.

Is there a way to do this using the Tap EventListener?

Thanks,
Steve [import]uid: 8919 topic_id: 5025 reply_id: 305025[/import]

I’ve never done it, but I recall seeing something about someone using an invisible object and then setting a tap event for that object. You’d just position it at the location where you want to watch for a tap.

Something like…

local foo = display.newRect(0, 294, 320, 480-294) foo.isVisible = false foo.isHitTestable = true foo.addEventListener("touch", fooGotHit)

That should put a tappable (invisible) square at the bottom of the screen.

Maybe that will get you headed in the right direction?

Jay [import]uid: 9440 topic_id: 5025 reply_id: 16480[/import]

Okay, that didn’t work. Even though the rect is set to invisible, I’m still seeing a white square on the screen.

I did get it to work with this kind of thing:

[code]local function removeCan(event)
if event.phase == “began” and event.y > 294 then
can.isVisible = false
end
end

Runtime:addEventListener(“touch”, removeCan)[/code]

…but you mentioned having problems with that kind of approach so maybe someone will come alone with a better answer.

Jay [import]uid: 9440 topic_id: 5025 reply_id: 16581[/import]

payjo,
Could you just create a fully transparent png graphic file the size you need, place it in the location and then add a touch event to it? I am not sure if that is any better, but it should work as well.

-edit sorry, meant to say payjo, not Jay… [import]uid: 13512 topic_id: 5025 reply_id: 16594[/import]