How to avoid 'picking' the background.

19 July 2017 23:04
Hey all, hope you're all well.

I'm using a pick object function, like this:

  function main_canvas_down(e) {

   var x = m_mouse.get_coords_x(e);
   var y = m_mouse.get_coords_y(e);

   var obj = m_scenes.pick_object(x, y);
   if (obj)

Which works. Only thing is, I'm getting a console error, when I click anywhere OTHER than the object, that reads: 'TypeError: null is not an object (evaluating 'obj.type')'

There's probably a simple way of avoiding this, but I'm not sure what it is. Anyone?

19 July 2017 23:18
I can't see the rest of your code, but somewhere, you are probably doing something with your obj that requires it not to be null. So you would need to varify non-null fitst.
if (obj != null)
Please register or log in to leave a reply.