In this post I’ll be introducing the Gamepad and Mouse Lock APIs, two additions to Firefox that are paving the way for high quality games on the Web.
The Gamepad and Mouse Lock APIs are just two of the new additions coming to Firefox that are going to help mature this platform. We’ll be posting more about them as they develop but let’s take a quick look at them today.
Breaking free from the keyboard with the Gamepad API
The Gamepad API is being worked on at Mozilla by Ted Mielczarek and others from our Paladin team.
Use it today
You can use the Gamepad API today in a custom build of Firefox, that also contains the Mouse Lock API (more details on that below). When you have installed the build you can then use the demonstration file to test it out. The wiki page contains information about implementing the API in your own project.
I have put together a short video showing off the Gamepad API an action with an xBox 360 controller:
Making the mouse behave with the Mouse Lock API
Until recently, it has been impossible to lock down the mouse cursor and contain movement within the browser. This has made it incredibly difficult for developers to implement games and visualisations that allow a player to look around in a large or 3D world. What would happen is the player would start looking around but would be prevented from looking when the mouse would go off the edge of the browser or hit the side of the monitor.
The Mouse Lock API solves this by hiding the cursor and locking it to the centre of the screen. When the API is enabled and the mouse is moved the developer is given details about the distance the mouse has travelled, rather than the coordinates of the mouse on the screen. These distance values allow infinite movement on the X and Y axis, letting the player to look around a 3D world without hitting any restrictions.
It is being worked on at Mozilla by David Humphrey and his students at Seneca College in Canada.
Use it today
David has also put together a short video showing off the Mouse Lock API in action:
The Mouse Lock API has a draft W3C specification edited by Vincent Scheib from Google. Find out more about our progress with the Mouse Lock API on Bugzilla. You can also check out David Humphrey’s series of posts on the development of the Mouse Lock API.