@AnscaTeam and whoever else may know…
Case:
I have a display object (sprite, image, primitive shape… can be whatever).
Goal:
I want to register a “touch” listener that will be of different shape/size than that of the display object. In my game I am going to have some small display objects, which I want the user to be able to touch without problems.
Approach1:
I can make a function that takes the object, makes a group and a primitive (transparent) shape and then inserts the object and the shape into the group. So, I can register the listener to the shape (of custom size, according to the Goal) and when something is listened I can act on the object itself, inside the event handler. However, instead of the object I should now transform the group to have the listening shape “follow” the object.
Problem:
That solution works, but I don’t like it! It is not flexible, as I have to know which object has a listener and which hasn’t, to call the group or the object itself when transforming.
Thoughts:
If only objects could have “children” by themselves (if they inherited from an abstract container class and not the opposite -as groups do inheritting from display objects) Corona would be more powerful!
Approach2:
I can write an object builder, which would make a group (as my major object), put the desired display object and the helper shape inside and then return the group (so I always transform the group itself and not the object-or-group like in Approach1). The listeners can be registered for the helper shape which will always follow the group. I just have to deep-call the display object for handling things like playing sprite’s animations etc. Things like location, alpha etc are directly mofied on the parent-group.
QUESTION:
Can you think of any other approach to implement custom-sized sensors for touch-handling?
How do you find Approach2? Is it somewhat bloated from the start? [import]uid: 7356 topic_id: 3691 reply_id: 303691[/import]
[import]uid: 5750 topic_id: 3691 reply_id: 11507[/import]