Virtual Gamepad Phaser Plugin

Virtual Gamepad Plugin for Phaser

Virtual Gamepad Phaser Plugin

I am currently working on a simple arcade game intended for smartphones, and after some research, I decided to develop it using JavaScript and Phaser. Getting an arcade-style controller on a mobile app requires a specialized “joystick” (the accompanying buttons are fairly straightforward). The basic concept is to have an area where a player can touch that determines the direction and distance of the joystick. The “joystick” should also be limited in how far it moves. The main game loop polls the joystick for information like angle and distance.

I found a few existing options in Phaser. The first is the beautiful and well-designed Virtual Joystick Plugin, but it costs $16. The next is an implementation of a Virtual Gamecontroller that creates a d-pad using buttons, which is useful, but lacks the analog nature of a true joystick. Finally, I found Eugenio Fage’s Touch Control Plugin.

The Touch Control Plugin worked almost exactly how I expected a virtual joystick to function, but instead of being in a static location on the screen, the user had to touch somewhere in the canvas to make the “joystick” appear. By examining how Eugenio performed the joystick calculations, I was able to make a static joystick overlay. The main difference is that Eugenio’s code uses events to determine presses on the joystick, and I found it to be sluggish when paired with a button. Like a bad JavaScript programmer, I changed it to polling (which Phaser does anyway in its update loop).

VirtualGamepad in action

To use the joystick, press down with your finger/thumb/mouse over the joystick area, and the “pad” should follow your pointer (out to a certain distance from the joystick’s center). The direction, rectangular, and polar properties should update accordingly. The button on the right should be fairly self-explanatory. A game using the Virtual Gamepad plugin just needs to poll the joystick and button’s properties on every update.

The most recent source code for the Virtual Gamepad plugin can be found on GitHub: https://github.com/ShawnHymel/phaser-plugin-virtual-gamepad/

A playable demo of the Virtual Gamepad in action can also be found on GitHub: http://shawnhymel.github.io/phaser-plugin-virtual-gamepad/

Crazy light pattern from LED light refracted through a bottle

Crazy Light Patters Using an LED and a Mini Booze Bottle

Crazy light pattern from LED light refracted through a bottle

I’d say I’m well on my way to creating my own Eye of Sauron

I had a burning desire to create some sort of electronics project with mini alcohol bottles (the ones you find in hotel rooms). My first instinct was to make them light up using LEDs. Since most are clear glass, light simply passes right through the bottle’s walls. However, the bottom is often curved, presenting a concave surface.  If you shone an LED through the bottle’s mouth, the curved glass acted as a perfect lens to refract the light, which further focused the already-narrow beam from the LED. In effect, you could only see the LED’s full brightness by looking at the bottle’s bottom straight on.

Continue Reading