Avg. Rating 4.3

Problem

You want to develop a game in Adobe AIR and want it to be controlled via Wii remote.

Solution

Use a third party tool to provide you with connection for reading data from the Wii remote and develop the rest of the functionality within Adobe AIR.

Detailed explanation

First of all be aware this is a Mac only recipe, altough if you read it and go trough the source codes attached you will be able to find your way under Windows as well.

Adobe AIR does not provide an API for connection with a Wii remote control, though it provides a socket API. Luckily out there is a little tool called MoteDeamon.
The MoteDeamon uses the Bluetooth of your Mac to find Wii remotes in range and establish connection to them. Once connected the MoteDeamon strams all Wii remote data to a local port.

You can find this third party software at this address : http://screenfashion.org/releases/motedaemon/

In the package you will find a ActionScript library to include in your code providing easy access to the incoming data. If you are developing HTML/JS AIR application you will find in the attached to this article source codes a client in JavaScript as well (ported by me).

To get started make sure the Bluetooth of your Mac is turned on. Start the MoteDeamon and pres simultaniously buttons "1" and "2" to get connected to the Mac.
Now you should be able to read data from Adobe AIR on port 45054 on the localhost.

Connecting to the server is pretty easy :

        wiiRemoteClient = new WiiRemoteClient();
        wiiRemoteClient.onServerConnected = function() {
            //do some initialization here
        }
        wiiRemoteClient.onServerConnectionFailed = function() {
            alert('failed to connect, check of your bluetooth is on')
        }
        wiiRemoteClient.connect('127.0.0.1', 45054); //connects to the local host

 

That should get you connected and once you are you just need to handle the incoming data from the remote :

 

        wiiRemoteClient.onAxisValue = function(address, wx, wy, wz, wr, wp, nx, ny, nz, jx, jy) {

          //here you need to process the incoming values from the remote,
          // though there's no good documentation around how to best handle the values
          // coming from the accelerometers , for a simple demo see the attached application

        }

 

The attached application shows how to connect to the server, read data, detect if the Wii remote is leaning left or right and detecting hits with the remote.


I'm sure all game JavaScript developers out there can create amazing applications for Adobe AIR and Wii remote.

wii1.air.zip
[Sample application demonstrating reading wii remote position and slaps]
wii.jpg

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes