Loading ...
Sorry, an error occurred while loading the content.

Best way to allow for clicks? Collision detection? Events?

Expand Messages
  • Andrew
    If I have ui elements in a canvas that I want to be clickable - what is the best way to go about doing that? Do I need to create some kind of collision
    Message 1 of 2 , Nov 12, 2008
    • 0 Attachment
      If I have ui elements in a canvas that I want to be clickable - what
      is the best way to go about doing that? Do I need to create some kind
      of collision detection to see if the mouse x,y is in a region? Or is
      there some better way?
    • Richard Heyes
      ... You can: 1. Attach a function to the canvas onclick event 2. Get the mouse coords from the resultant event object. 3. Those, combined with some magic, will
      Message 2 of 2 , Nov 12, 2008
      • 0 Attachment
        > If I have ui elements in a canvas that I want to be clickable - what
        > is the best way to go about doing that? Do I need to create some kind
        > of collision detection to see if the mouse x,y is in a region? Or is
        > there some better way?

        You can:

        1. Attach a function to the canvas onclick event
        2. Get the mouse coords from the resultant event object.
        3. Those, combined with some magic, will help you get the position of
        the mouse cursor.

        Below is a function which I use. If nested within a TABLE though, it
        doesn't seem to work. :-( Any amount of DIV nesting does though. You
        can see it in action here: http://dev.rgraph.org The top graph has
        clickable bars.

        http://www.phpguru.org/downloads/mousecoords.txt

        --
        Richard Heyes

        HTML5 Graphing for FF, Chrome, Opera and Safari:
        http://www.rgraph.org (Updated November 1st)
      Your message has been successfully submitted and would be delivered to recipients shortly.