June 21, 2007

WiiFlash fun

Writing about web page http://www.wiiflash.org

I spent last night playing with a Nintendo Wiimote in Flex, using the cool WiiFlash API. Setting it up is easy – firstly hook your Bluetooth connection to the Wiimote and start up the WiiFlash server. Then in FlexBuilder, link the WiiFlash SWC library to your project and off you go. Here’s the simple demo code I created; on pressing the B button it reads and reports the Wiimote pitch and yaw values, rotates an image based on the raw pitch value and adds some rumble for effect.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">
    <mx:Script>
        <![CDATA[
    [Bindable]
            public var roll:Number;
        [Bindable]
            public var yaw:Number;
            public function initApp():void
            {
                var myWiimote:Wiimote;
                import flash.display.Sprite;
                import org.wiiflash.Wiimote;
                import org.wiiflash.events.ButtonEvent;
                import flash.events.Event;
                myWiimote = new Wiimote();
                myWiimote.connect("localhost", 0x4a54);
                myWiimote.addEventListener(Event.CONNECT, onConnect);
                myWiimote.addEventListener(ButtonEvent.B_PRESS, onBPress);

                function onConnect():void
                {
                    trace("Wiimote connected :-)");
                }
                function onBPress(evt:ButtonEvent):void
                {
                    trace("B Button" + evt.state);
                    myWiimote.rumble = true;
                    myWiimote.rumbleTimeout = 150;
                    getPosition();
                }
                function getPosition():void
                {
                    roll = myWiimote.roll;
                    yaw = myWiimote.yaw;
                }
            }
        ]]>
    </mx:Script>
    <mx:VBox x="26" y="29" height="100%" width="344">
        <mx:Text text="Wiimote position:" fontSize="15"/>
        <mx:Text id="roll_txt" fontSize="18" text="Roll: {roll}"/>
        <mx:Text id="yaw_txt" fontSize="18" text="Yaw: {yaw}"/>
        <mx:Image source="c:\winter.jpg" width="200" height="150" rotation="{roll}" horizontalCenter=""/>
    </mx:VBox>
</mx:Application>

For my next trick, I shall make the LEDS dance a little display, but I’m really just waiting for the Papervision 3D framework to become available so I can try manipulating 3D models with this. As I’m using FlexBuilder 3 Beta I might also try making a simple AIR desktop game that uses the Wiimote.


- No comments Not publicly viewable


Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

Search:

MXNA link

Tweets



    Tags

    Other blogs I like...

    Black Pepper Software

    Emak Mafu

    Eismann-sf Go to 'Comments on: Design News for Web, Graphic Designers'

    Ted On Flex Go to 'Ted On Flash'

    Galleries

    Meetups:

    Not signed in
    Sign in

    Powered by BlogBuilder
    © MMXIX