On 08/22/2011 03:36 AM, Amit Agarwal wrote: > Hi, > > I am working on a WebGl based prototype where in I have drawn multiple > shapes. For example, I have one triangle and one square. You can dispatch events yourself. I have a page on the solution I use which allows each shape to register for a particular type of event, passing a routine to be called to see if there's a hit, and if so a routine to callback with the event. I did it this way (I'm using a 2d context, but it shouldn't make a difference for this), because I wanted a lot of different things to be able to register and figured each of them would know if something should apply to them. The hit() routines get passed an (x,y) pair in canvas coordinates and returns true or false.
There would be other situations where it would make more sense for a central routine to walk the tree and figure out if something was hit, for example if you care about overlaps. An individual object won't know if it is covered. Here's a link to a page that discusses it a lot more along with links to the code. http://dbp-consulting.com/tutorials/canvas/CanvasEventDelegation.html There's some mention of some proposed solutions in html5 for this by adding objects but it's just a discussion, there's no real implementation, and people are arguing about what it means. So far you need to create your own solution. I use it in several things, including for the buttons and sliders on http://dbp-consulting.com/tutorials/canvas/CanvasGameOfLife.html. The buttons are just drawn on the canvas, but they get the events from the canvas and respond. The sliders respond to keys and rollers, and touch screen taps and slides. Code wants to be free but needs attribution and copyright intact. Probably it won't be exactly what you need but will give you ideas. My ideas are free:) Pass it on. Hope this helps. Patrick -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
