Jump to content

Canvas CSS border affects mouse x/y calculations


botman
 Share

Recommended Posts

Hello,

 

I couldn't see reference to this, but apologies if I overlooked something obvious. I tried to search for existing bug reports in GitHub or the forum here, but the forum doesn't let me search the word 'border'.

 

I set up a simple example where I had a sprite that could be hovered over/clicked on, etc. E.g:



var foo = game.add.sprite( 100, 100, 'foo' );
foo.inputEnabled = true;
foo.input.useHandCursor = true;


However, I had included a border via CSS around the canvas element Phaser was drawing to. E.g. 



canvas {
border: solid 10px #111;
}


As a result, the calculation for if or not the mouse is over a given sprite is off by whatever the width of the border is. This is on latest Chrome on Windows and Mac.

 

The easy fix for me is to not have the border, but I was scratching my head for a while as to why something seemingly so basic wasn't working. 

 

Simple example here: http://botman.com.au/phaser/test/

 

Thanks for all your hard work!

 

Regards,

Chris

Link to comment
Share on other sites

Yeah I agree, it's certainly easy to get around this, the bigger issue is it should maybe be highlighted in the docs or something, as I originally had the problem on a more complex game I'd been working on and couldn't for the life of me work out why clicking on sprites was out. I thought it might be something to do with scaling, so I spent a few hours stripping back code trying to find the base example that would trigger what appeared to be a bug. In the end it of course wasn't anything in the JS.

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...