Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #32504

Re: Find element/object below mouse

Newsgroups comp.lang.javascript
Date 2017-02-06 11:56 -0800
References <f29d15a6-d5d3-49eb-907c-52a8972d3444@googlegroups.com> <sle60fn8jola.7jj05r2oxc55$.dlg@40tude.net> <f59154bf-68d8-4443-b1a6-ffffa6df1791@googlegroups.com> <5898b9fa$0$1685$e4fe514c@newszilla.xs4all.nl> <5edf2b75-edc4-4f31-9283-7d14c5e52f55@googlegroups.com>
Message-ID <d2a75b1d-9ce3-48af-9f4b-33d36afb2bfc@googlegroups.com> (permalink)
Subject Re: Find element/object below mouse
From jonas.thornvall@gmail.com

Show all headers | View raw


Den måndag 6 februari 2017 kl. 20:20:22 UTC+1 skrev jonas.t...@gmail.com:
> Den måndag 6 februari 2017 kl. 19:02:20 UTC+1 skrev Silvio:
> > On 02/06/2017 05:30 PM, jonas.thornvall@gmail.com wrote:
> > > Den måndag 6 februari 2017 kl. 14:03:06 UTC+1 skrev JJ:
> > >> On Sun, 5 Feb 2017 21:29:17 -0800 (PST), jonas.thornvall@gmail.com wrote:
> > >>> I have an array with rectangle elements?/objects? painted on canvas, right
> > >>> now i do poll the full array comparing mouse position from eventhandler
> > >>> with the array elements. And determine if to move it by click and hold.
> > >>>
> > >>> So at every redraw i basicly do the check, because i do not know, the
> > >>> standard way to do it.
> > >>>
> > >>> http://anybase.co.nf/
> > >>>
> > >>> The approach work but i wonder is there a more effective and a standardid
> > >>> way to do this in javascript?
> > >>>
> > >>> The way i do it would be ineffective if there is thousands of objects,
> > >>> then it would be better to poll subareas of canvas, but then each
> > >>> arrayelement somehow need to know which area and span of cordinates it do
> > >>> belong to "set a property or attribute of the nodeobject. And you would
> > >>> have to check if the node have the property rather than they x,y
> > >>> cordinates, so i am not sure you even win that much.
> > >>>
> > >>> Because now i will also include mark, create and remove and translate
> > >>> copy/paste group array elements/objects to new position. So any necessary
> > >>> changes to the whole approach would be better todo before rather than
> > >>> after.
> > >>
> > >> Your canvas "objects" is only in your script's mind. Canvas only sees
> > >> pixels. You'll have to do it manually for each canvas "object" you create
> > >> like any other games in any platform.
> > >
> > > Ok then my approach seem sound.
> > > Thanks
> > >
> > 
> > It does not mean that you need to have a linear lookup, of course.
> 
> How could it otherwise be done? The mouse events is not aware about the rectangles? And the rectangles isn't aware about the mouse position?

I do not think there would be less work to sort to nearest mouse node then to actually poll the full list?

For a short while i was thinking dividing canvas into subareas but i am not sure it is worth it? 

What approach did you have in mind, and can you explain in layman terms or give me a pointer to example on web?

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Find element/object below mouse jonas.thornvall@gmail.com - 2017-02-05 21:29 -0800
  Re: Find element/object below mouse JJ <jj4public@vfemail.net> - 2017-02-06 20:03 +0700
    Re: Find element/object below mouse jonas.thornvall@gmail.com - 2017-02-06 08:30 -0800
      Re: Find element/object below mouse Silvio <silvio@internet.com> - 2017-02-06 19:01 +0100
        Re: Find element/object below mouse jonas.thornvall@gmail.com - 2017-02-06 11:20 -0800
          Re: Find element/object below mouse jonas.thornvall@gmail.com - 2017-02-06 11:56 -0800
            Re: Find element/object below mouse jonas.thornvall@gmail.com - 2017-02-06 11:59 -0800
          Re: Find element/object below mouse JJ <jj4public@vfemail.net> - 2017-02-07 22:35 +0700
            Re: Find element/object below mouse jonas.thornvall@gmail.com - 2017-02-07 07:46 -0800
    Re: Find element/object below mouse Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-02-09 02:07 +0100

csiph-web