Jump to content

Recognising when a user is clicking below a particular sprite


davro12345
 Share

Recommended Posts

I have a game, built using pixi.js, where I want to run some code every time the user presses below a certain sprite. I am handling the press event using hammer.js. The problem is that the y attribute of the sprite and the y attribute of the user’s touch event don’t match what I can see on my screen. As, an example, consider the code below:

if (touchPointer.clientY > this.children.marker1.position.y) {

console.log("******* Clicked Below the Line ********: ");} else{

console.log("******* Clicked Above the Line ********: ");}

The problem I have is that, when I click slightly above the sprite, the first section of code will run (which prints “Clicked Below the Sprit”), even though on the screen, I can clearly see the pointer is above the sprite. I am guessing, what’s going on is that the y positions for the pointer and the sprite are being calculated differently, but I don’t know how to go about ensuring they’re calculated consistently, so I can properly compare sprites against the pointer. After doing some research, I think the problem, more specifically, might be that I need to convert "screen coordinates" to "world cordinates". I'm not really familiar with the difference between "screen coordinates" and "world cordinates", but presumably the y position of the pointer is being calculated using "screen cordinates", and I need to convert these coordinates into "world cordinates", but I don't have any idea how to do this. Any suggestions?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...