Jump to content

Check if mouse is available


Andromedus
 Share

Recommended Posts

Hey guys,

Is there a way in Phaser to check if a mouse is available?  So far I've been using if(game.device.touch) in my code to distinguish between desktop and mobile devices, but as many desktops/laptops have touch as well, they will be treated as mobiles in my code, which isn't what I want.

Thanks. 

Link to comment
Share on other sites

@Andromedus, what do you exactly want to achieve? I am asking because there is no real straightforward answer to this. There are workarounds but they all depend on the final result.

To give you a first and quick answer: you could treat any device with touch input as a touch-only device until you get some sort of continuous 'mouseMove' event, in that case, you can switch to mouse.

Link to comment
Share on other sites

Thanks Nesh - so basically, I have two different control methods in my game, one for where a mouse is available, and one for where touch is available.  It only just occurred to me that some have both mouse and touch enabled (like a desktop with a touch screen monitor), and was trying to figure out a ) how to detect that and b ) what to do in that scenario.  But if there is no way to check if there is a mouse plugged in, that's going to be awkward.  I get what you're saying, you can check for mouseMove events, but I assume that would also detect input from a track pad on a laptop, which wouldn't be a very easy way to play the game.  I think I'll just stick with how it is already, so if touch is enabled, they'll get the touch control method, like it or lump it.  I suppose I could work in a setup screen to give people the option but that seems like a bit of a faff - I'd rather keep things simple and get straight into the game. 

Link to comment
Share on other sites

5 hours ago, Abhishek Singhal said:

Hi Andromedus,

I am new to Phaser not very sure on this.
Going by the name, maybe we could check for "game.input.mousePointer", It should be undefined if a mouse cursor is not available considering the device to be a touch enabled device. 

 

That would be quite interesting to see as in pure javascript, as far as I know, there is not straightforward way to find if the mouse if available or not. :D

Let us know, @Andromedus!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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