Class com.wiicade.WiiRemote

Description

This class provides information about the current state of a given Wii Remote. This interface supports up to 4 remotes, their button states, twist angles, connected statuses, cursor positions, and whether or not the remotes are facing the screen. Note that this class should not be used directly, but should be obtained through either Wii.getRemote(<id>) or Wii.getPrimaryRemote().

Button states can be to polled to determine whether a given button is pressed or not. To determine this information, call the isDown() function with one of the following WiiRemote constants:

Constant
BUTTON_UP
BUTTON_DOWN
BUTTON_LEFT
BUTTON_RIGHT
BUTTON_1
BUTTON_2
BUTTON_A
BUTTON_B
BUTTON_PLUS
BUTTON_MINUS


The Home key is reserved for use by the Nintendo Wii and is not mapped. The following is an example of how you would check if the B button is pressed on the Nintendo Wii Remote:

if(Wii.getPrimaryRemote().isDown(WiiRemote.BUTTON_B)) { ...do logic... }

Field Index

BUTTON_1, BUTTON_2, BUTTON_A, BUTTON_B, BUTTON_DOWN, BUTTON_LEFT, BUTTON_MINUS, BUTTON_PLUS, BUTTON_RIGHT, BUTTON_UP

Method Index

addEventListener(), getAttachment(), getCursorX(), getCursorY(), getDistance(), getIdentity(), getTwistAngle(), isConnected(), isDown(), isFacingScreen(), isPrimary(), isRotated(), removeEventListener(), setRotated()

Field Detail

BUTTON_UP

static public BUTTON_UP:Number

BUTTON_DOWN

static public BUTTON_DOWN:Number

BUTTON_RIGHT

static public BUTTON_RIGHT:Number

BUTTON_LEFT

static public BUTTON_LEFT:Number

BUTTON_1

static public BUTTON_1:Number

BUTTON_2

static public BUTTON_2:Number

BUTTON_A

static public BUTTON_A:Number

BUTTON_B

static public BUTTON_B:Number

BUTTON_PLUS

static public BUTTON_PLUS:Number

BUTTON_MINUS

static public BUTTON_MINUS:Number

Method Detail

getIdentity

public function getIdentity():Number

Each Wii console is capable of connecting to up to four Wii Remotes. Each of these remotes has a numerical identity. These identites range from 0 for the first remote to 3 for the fourth remote. This function returns the numerical identity of this remote.

Return

The identity of this Wii Remote. Possible values are 0, 1, 2, and 3.

isPrimary

public function isPrimary():Boolean

If this remote is the one currently able to interact with the webpage, this function will return true. See Wii.getPrimaryRemote() for more information.

Return

true if this remote is the primary, false otherwise

isConnected

public function isConnected():Boolean

This function can be used to determine if a Wii Remote is powered on or not. Remotes that are connected to the Wii return true, while remotes that are powered off or non-existant return a value of false.

Return

true if the remote is powered on, false otherwise

isRotated

public function isRotated():Boolean

Returns true if the interface is configured to use the Wii Remote in a sideways configuration. False is returned if the remote is configured for vertical use. The default value is false.

setRotated

public function setRotated(rotate:Boolean):Void

Switches the Wii Remote between vertical configuration and sideways configuration. Default is false for vertical configuration. This setting is ignored when not running on a Nintendo Wii.

Parameters

rotateTrue for sideways configuration, false for vertical configuration.

getTwistAngle

public function getTwistAngle():Number

This function provides the angle of rotation of the remote when rotated with the wrist. Because this feature uses the IR sensor on the front of the remote, this information is only updated when the remote is facing the screen. Since the Wii cursor utilizes the same information, the rotation of the cursor will match the value returned by this function.

If the remote is pointed away from the screen, the last known angle will be reported. If this presents a problem for your game, use the isFacingScreen() function to determine whether this value is currently being updated or not.

The value returned is in the range of 0 to 359 degrees. To translate this value to a range of -180 to +179, simply subtract 180 from the value returned. e.g.:

var angle = Wii.getPrimaryRemote().getTwistAngle() - 180;

Return

A value between 0 and 359 representing the angle of rotation.

getDistance

public function getDistance():Number

This function provides the Wii Remote's distance from the screen. This feature makes use of the IR Sensor on the front of the remote, and only operates when the remote is facing the screen. This function can return values between 0 and 800. However, the minimum value when in use appears to be 52. A value of 0 is returned when distance information is not available.

Return

A value between 0 and 800 representing the Wii Remote's distance from the television.

getCursorX

public function getCursorX():Number

Returns the X coordinate of the cursor on the screen. Coordinates are automatically mapped to the coordinate-space of the flash movie. Thus this function should return the same result as _mousex would. The primary difference is that this interface is capable of returning values outside the range of the movie. So it is possible to get a negative value or a value larger than the width of the movie.

Note that the standard mice features work in Flash on the Wii, but only for the primary remote. If you wish to support more than one remote, you will need to use this function instead.

Return

An integer representing the current screen X position of the cursor.

getCursorY

public function getCursorY():Number

Returns the Y coordinate of the cursor on the screen. Coordinates are automatically mapped to the coordinate-space of the flash movie. Thus this function should return the same result as _mousey would. The primary difference is that this interface is capable of returning values outside the range of the movie. So it is possible to get a negative value or a value larger than the height of the movie.

Note that the standard mice features work in Flash on the Wii, but only for the primary remote. If you wish to support more than one remote, you will need to use this function instead.

Return

An integer representing the current screen Y position of the cursor.

isFacingScreen

public function isFacingScreen():Boolean

This function allows you to determine if the remote is facing toward the screen or away. This information is important as many of the Wii Remote's features only work while the controller is facing the screen.

Other interesting uses for this function include auto-pausing of the game ala the "spotlight" feature in Super Paper Mario. It can also be used to automatically rotate the controller's interface if the controller is facing away from the screen.

Return

True if the remote is facing the screen, false otherwise.

isDown

public function isDown(buttonCode):Boolean

Use this function to check if a Wii Remote button is pressed.

Parameters

buttonCodeOne of the WiiBrowser.BUTTON_<name> constants.

Return

True if the button is pressed, false if not.

getAttachment

public function getAttachment()

Returns an interface to the current Wii Remote attachment. As of the current version, only the Nunchuk is supported.

Return

An instance of the Nunchuk object.

addEventListener

public function addEventListener(type:String, listener:Function):Void

This function can be used to register an event listener for any of the following events:

  • buttondown - One of the Wii Remote buttons has been pressed.
  • buttonup - One of the Wii Remote buttons has been released.
  • twist - The angle of Wii Remote's rotation has changed.
  • distance - The distance from the screen has changed.
  • connected - This Wii Remote has been connected.
  • disconnected - This Wii Remote has been disconnected.
  • pointer - The cursor X and Y positions have changed.
When an event occurs, the passed-in function gets called with a parameter containing information about the event. All events attach a variable to the parameter called "identity". This is the id of the remote that fired the event. Each event type may have additional variables attached.

Here is a list of possible variables and the event types they are attached to:
  • buttonCode - buttondown, buttonup
  • angle - twist
  • distance - distance
  • cursorx - pointer
  • cursory - pointer
Here's an example of how this function might be used:
 Wii.getPrimaryRemote().addEventListener("buttondown", onButtonDown);
 
 function onButtonDown(event)
 {
     if(event.buttonCode == WiiRemote.BUTTON_B)
     {
         trace("The B button was pressed on remote #"+event.identity);
     }
 }

Parameters

typeA string representing the type of event to listen for.
listenerThe function to call when the event is fired.

removeEventListener

public function removeEventListener(type:String, listener:Function):Void

This function removes a listener previously registered with addEventListener.

Parameters

typeA string representing the type of event to listen for.
listenerThe function to call when the event is fired.