There is an open problem in porting real game into the web browser related to cursor handling. But before we jump into that, you might actually find these selection of casino bonuses fascinating. You can get free spins and credits by registering an account as a welcome bonus for new players like you.
Problem
Many games such as First-Person Shooters require the mouse to freely move, without the constraints of screen edges. However there is no such API in the browser to make this work.
If you don't know what I mean, you can experience it yourself on the CopperLicht Quake 3 Map Demo. You will find it really hard to move because there is no way to reproduce the standard FPS cursor behavior.
This important issue does not occur only on First-Person Shooter games. For example in World of Warcraft, you can Left/Right-click and drag in order to move the camera. During the dragging operation the cursor is hidden. When the operation is over, the cursor re-appears at the position it was when the dragging started.
Proposal
The behavior is usually implemented moving back the cursor to the center of the screen at every moment. Therefore, a way to solve the problem would be to implement an API that lets us set the cursor position.
However, in most games, we don't need to actually control the mouse. Instead, we want to hide the cursor and make the mouse freely move around, without being limited by the size of the screen.
This is why I suggest the addition of a mouseFreeze
function. The mouse will be anchored to that position and the mousemove
events are going to set a virtual
position.
window.mouseFreeze() // The cursor is hidden addEventListener(window, 'mousemove', function (event) { // Everytime the user moves the mouse // The delta is added to "virtual[X/Y]" // The cursor is moved to the center of the screen event.pageX, event.pageY // Cursor Real Position event.virtualX, event.virtualY // Cursor Virtual Position }); window.mouseUnfreeze() // The cursor is shown // The cursor is moved to the position it was frozen |
Open Questions
I believe that mouseFreeze
API is a solution that enables a wide range of games to be ported into the browser while being an order of magnitude less dangerous than giving total mouse control.
The mouseFreeze
is currently only an idea and it raises many questions such as
- How to make sure you can't get stuck in frozen state?
- Can it be exploited?
- What if the user scrolls?
- What if the user alt-tabs?
- Add events
onmousefreeze
,onmouseunfreeze
? - Allow it only on fullscreen applications?
I am welcoming any feedback on this idea. If you believe it is a good one and are interested in writing a patch for Chrome/Firefox/Opera, I would love to help you out.
References
mashu on Hacker News mentioned that this issue is being worked on in a Chrome Bug. This is an interesting read that proposes alternative solutions and gives more use cases.