How do I simulate on click on object when object changes position with Anchor behaviour in JS?

0 favourites
  • 2 posts
From the Asset Store
Customize the animation of character when item changed
  • Hi. What I want is pretty simple. So I have this function running on pointerdown. The thing is that the e.clientX/Y gives me the coordinates for the pointer in the current browser position, and then I get all the polypoints from the obj and then make an array with all the points and send to the tools.inside() function to check if that click is inside that polygon. This works fine if the obj doesn't move. But I have the objects with Anchor behaviour and they move. So what happens is that the polyPoints array is using the coordinates of the obj in the original game resolution (540 x 270). But the pointer uses the window position coordinates with the current resolution from the browser (915 x 412). So when I check if the point is inside the polygon it doesn't match.

    I have tried changing the point position from one resolution but it doesn't work. Is there any function or way to make this work ?

    Thanks

     runtime.addEventListener('pointerdown', (e) => {
     let view = e.runtime.getViewportSize();
     let x = e.clientX - ((window.innerWidth - c3canvas.clientWidth) / 2);
     let y = e.clientY - ((window.innerHeight - c3canvas.clientHeight) / 2); 
     let arr = [];
     
     for (let j = 0; j < obj.getPolyPointCount(); j++){ 
     arr.push([
     ((obj.getPolyPointX(j) * c3canvas.clientWidth) / view[0]),
     ((obj.getPolyPointY(j) * c3canvas.clientHeight) / view[1])
     ]);
     }
     
     if(tools.inside(x,y, arr) && obj.isVisible) {
     this.CallFunction(func);
     } 
     });
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Forget it I found the solution use layer.cssPxToLayer(e.clientX, e.clientY); function explained here: construct.net/en/make-games/manuals/construct-3/scripting/scripting-reference/layout-interfaces/ilayout/ilayer

    Thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)