How do I check if object contains point ?

Not favoritedFavorited Favorited 1 favourites
  • 1 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • Hi,

    So my project is all in JS and I noticed that if I change the Fullscreen mode to 'Scale outer' the containsPoint(x, y) fails.

    I have a UI layer with Parallax set to 0 in both axis. And I click in the button but it doesn't trigger. My code use to be like this.

    this.i is the instance of that object.

     const myPointerDown = (e) => {
     const l = run.getLayer(layer);
     const [x, y] = l.cssPxToLayer(e.clientX, e.clientY);
    
     if (this.i.containsPoint(x, y)) {
     this._call(f);
     }
     };

    But now this fails after changing the Fullscreen mode. So I made this functions to check if the point is inside the polygon, and looks like this.

     const myPointerDown = (e) => {
     const l = run.getLayer(layer);
     const [x, y] = l.cssPxToLayer(e.clientX, e.clientY);
    
     let arr = run.getObjectPoly(obj);
    
     if (tools.inside(x, y, arr)) {
     this._call(f);
     }
     };
    

    But just happens that I have the same problem because when I use getPolyPointX(x) it gives the coordinates without taking in account the position change on the parallax 0 I guess because if I give it 100% to Y parallax it works fine. In terms of values the Y axis in the editor is 288 and should return ~351, having in account the viewport is 180x320 and I'm using a phone with 430x932. Anyone knows what is my problem and how to fix it ?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)