an image with multiple touch areas (zones)

Guys,

Is this possible, to have one big image with different touch zones defined? So when a user touches a particular section of the image, it fires the touch event for that section…

I can have one touch event and work out the x and y co-ordinates and work it out… but I want to know if a zone based solution exists

Thanks

Vik [import]uid: 67619 topic_id: 29732 reply_id: 329732[/import]

@vik_b_it ,

Yes, I think it is perfectly possible.

What you would do for example is:

– Place your “big” image (the one that you want to have many “zones” receiving “touch”;

– Create as many [lua]display.newRect()[/lua] as you want to become active as “touch`s area” (for receiving touch events) and place it over the “big” image

– Set the [lua].alpha[/lua] of these [lua]display.newRect()[/lua] for something like [lua]0.01[/lua] (so they become transparent/invisible for the user`s eyes - and yours too :slight_smile: )

– Add Event Listeners for all of them you want to receive events and voilá , you will have a “big” image (lets say taking all the [lua]display.contentWidth[/lua] and/or [lua]display.contentHeight[/lua]) and having many “active areas” over it (by those transparent Rects we`ve created above).

EDIT: And also you could use a property (as [lua]myTouchZone.name = “area 1” --and so on…[/lua] for easier future reference (in the code) for that “specific” touch active`s zone and also be knowing from where come the touch from.

EDIT2: This all could be done also having your “big” image as “many tiles” and giving these tiles an eventListener for each one too.

Got it?
Let me know if not. :slight_smile:
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 29732 reply_id: 119334[/import]

Totally agree with Rodrigo. I think there’s even a slight way to further improve it. Rather than set the alpha of your touch area rectangles to 0.01 (which means they are still ever-so-slightly visible), you can set their [lua]isVisible[/lua] property to false (so they’re completely invisible), but also set their [lua]isHitTestable[/lua] property to true (so that they still receives touch events).

  • Andrew [import]uid: 109711 topic_id: 29732 reply_id: 119340[/import]