WiiリモコンでAIRアプリを動かすんだよ
- re_shikajiro
- Wii , Air
- 2008年10月23日
Table of Contents
<div class="section">
<p>WiiFlashServerがあればwiimote(<a class="keyword" href="http://d.hatena.ne.jp/keyword/Wii%A5%EA%A5%E2%A5%B3%A5%F3">Wiiリモコン</a>のこと)と<a class="keyword" href="http://d.hatena.ne.jp/keyword/actionscript">actionscript</a>の連携ができるんだよ。</p>
<p>ということは、<a class="keyword" href="http://d.hatena.ne.jp/keyword/AIR">AIR</a>アプリをwiimoteで動かせるんだよ!</p>
<p>早速実装してみるよ。</p>
<p><a href="http://code.google.com/p/wiiflash/" target="_blank">WiiFlashServer Google Code</a></p>
<table>
<tr><th>必要な動作環境</th><th>鹿の環境</th></tr>
<tr><td><a class="keyword" href="http://d.hatena.ne.jp/keyword/WinXP">WinXP</a> or <a class="keyword" href="http://d.hatena.ne.jp/keyword/Vista">Vista</a> or <a class="keyword" href="http://d.hatena.ne.jp/keyword/MacOSX">MacOSX</a></td><td><a class="keyword" href="http://d.hatena.ne.jp/keyword/MacOSX">MacOSX</a></td></tr>
<tr><td><a class="keyword" href="http://d.hatena.ne.jp/keyword/bluetooth">bluetooth</a>アダプタ</td><td><a class="keyword" href="http://d.hatena.ne.jp/keyword/MacBook">MacBook</a>内蔵<a class="keyword" href="http://d.hatena.ne.jp/keyword/bluetooth">bluetooth</a></td></tr>
<tr><td>wiimote</td><td>愛用wiimote</td></tr>
<tr><td>WiiFlash 0.x.x.zip</td><td>WiiFlash 0.4.3.zip</td></tr>
</table>
<h4> swcを配置するよ</h4>
<p>Wiimoteを操るライブラリ、WiiFlash.swc を<a class="keyword" href="http://d.hatena.ne.jp/keyword/AIR">AIR</a>プロジェクトのlibsの中に入れるんだよ。</p>
<p>これだけでWiimoteを操れるよ!</p>
<h4> wiimote を<a class="keyword" href="http://d.hatena.ne.jp/keyword/bluetooth">bluetooth</a>に接続するよ</h4>
<p>serversフォルダのserverを実行するんだよ。</p>
<ul>
<li>winならWiiFlashServer x.x.x.exe</li>
<li><a class="keyword" href="http://d.hatena.ne.jp/keyword/mac">mac</a>ならzipファイルの中のWiiFlashServerJ</li>
</ul>
<p>あとはwiimoteの1と2を同時押しすれば、認識されるはずだよ!</p>
<h4> 動かしてみるよ</h4>
<p>簡単なソースを書いてみるよ。</p>
// Wiiリモコンインスタンスの生成 var wiimote:Wiimote = new Wiimote(); // 接続したらwiimote conectedを表示 wiimote.addEventListener( Event.CONNECT, function(event:Event):void{ trace("wiimote conected"); } ); // Wiiリモコンに接続 wiimote.connect();
<p><a class="keyword" href="http://d.hatena.ne.jp/keyword/Wii%A5%EA%A5%E2%A5%B3%A5%F3">Wiiリモコン</a>が接続できれば wiimote conected ログが出力されるはずだよ。</p>
<p>みんなもやってみるんだよ!</p>
<h4> 簡単なアプリを作るよ</h4>
<p>動作確認用アプリを作ってみるよ。</p>
<p>現在のWiimoteの情報を表示するだけのアプリだよ。</p>
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()" width="800" height="500"> <mx:Script> <![CDATA[ import org.wiiflash.IR; import org.wiiflash.events.WiimoteEvent; import org.wiiflash.events.ButtonEvent; import org.wiiflash.Nunchuk; import org.wiiflash.Wiimote; private var wiimote:Wiimote; public function init():void{ wiimote = new Wiimote(); wiimote.addEventListener( Event.CONNECT, function(event:Event):void{ trace("wiimote conected"); } ); wiimote.addEventListener( ButtonEvent.A_PRESS, function(event:ButtonEvent):void{ trace("wiimote A Pressed"); } ); wiimote.addEventListener( ButtonEvent.A_RELEASE, function(event:ButtonEvent):void{ trace("wiimote A Release"); } ); wiimote.addEventListener( WiimoteEvent.IR1_FOUND,function(event:WiimoteEvent):void{ trace("wiimote IR1 Found"); }); wiimote.addEventListener( WiimoteEvent.IR1_LOST,function(event:WiimoteEvent):void{ trace("wiimote IR1 Lost"); }); //nunchuk wiimote.addEventListener( WiimoteEvent.NUNCHUK_CONNECT, function(event:WiimoteEvent):void{ trace("nunchuk connected"); } ); wiimote.addEventListener( WiimoteEvent.NUNCHUK_DISCONNECT, function(event:WiimoteEvent):void{ trace("nunchuk disconnected"); } ); wiimote.nunchuk.addEventListener ( ButtonEvent.C_PRESS, function(event:ButtonEvent):void{ trace("nunchuk C Press"); } ); wiimote.nunchuk.addEventListener ( ButtonEvent.C_RELEASE, function(event:ButtonEvent):void{ trace("nunchuk C Release"); } ); addEventListener(Event.ENTER_FRAME, function(event:Event):void{ var wiimote:Wiimote = Wiimote(event.target.wiimote); wiimote_x.text = wiimote.sensorX.toString(); wiimote_y.text = wiimote.sensorY.toString(); wiimote_z.text = wiimote.sensorZ.toString(); wiimote_yaw.text = wiimote.yaw.toString(); wiimote_roll.text = wiimote.roll.toString(); wiimote_pitch.text = wiimote.pitch.toString(); //wiimote button wiimote_A.text = wiimote.a.toString(); wiimote_B.text = wiimote.b.toString(); wiimote_1.text = wiimote.one.toString(); wiimote_2.text = wiimote.two.toString(); wiimote_plus.text = wiimote.plus.toString(); wiimote_minus.text = wiimote.minus.toString(); wiimote_up.text = wiimote.up.toString(); wiimote_down.text = wiimote.down.toString(); wiimote_left.text = wiimote.left.toString(); wiimote_right.text = wiimote.right.toString(); wiimote_home.text = wiimote.home.toString(); var ir:IR = IR(wiimote.ir); ir_p.text = ir.p1.toString(); ir_size.text = ir.size1.toString(); ir_x.text = ir.x1.toString(); ir_y.text = ir.y1.toString(); var nunchuk:Nunchuk = Nunchuk(wiimote.nunchuk); nunchuk_stick_x.text = nunchuk.stickX.toString(); nunchuk_stick_y.text = nunchuk.stickY.toString(); nunchuk_x.text = nunchuk.sensorX.toString(); nunchuk_y.text = nunchuk.sensorY.toString(); nunchuk_z.text = nunchuk.sensorZ.toString(); nunchuk_yaw.text = nunchuk.yaw.toString(); nunchuk_roll.text = nunchuk.roll.toString(); nunchuk_pitch.text = nunchuk.pitch.toString(); //button nunchuk_C.text = nunchuk.c.toString(); nunchuk_Z.text = nunchuk.z.toString(); }); wiimote.connect(); wiimote.mouseControl = false; } public function mousControl():void{ wiimote.mouseControl = (wiimote.mouseControl ? false:true); } ]]> </mx:Script> <mx:Button x="299" y="428" label="wiimote MouseControl" width="200" height="50" click="mousControl()"/> <mx:Text x="10" y="10" text="wiimote x"/> <mx:Text x="273" y="10" text="nunchuk x"/> <mx:Text x="273" y="166" text="nunchuk stick x"/> <mx:Text x="273" y="192" text="nunchuk stick y"/> <mx:Text x="273" y="218" text="nunchuk C"/> <mx:Text x="373" y="218" id="nunchuk_C"/> <mx:Text x="373" y="244" id="nunchuk_Z"/> <mx:Text x="273" y="244" text="nunchuk Z"/> <mx:Text x="273" y="114" text="nunchuk roll"/> <mx:Text x="273" y="140" text="nunchuk pitch"/> <mx:Text x="373" y="114" id="nunchuk_roll"/> <mx:Text x="373" y="140" id="nunchuk_pitch"/> <mx:Text x="373" y="88" id="nunchuk_yaw"/> <mx:Text x="273" y="88" text="nunchuk yaw"/> <mx:Text x="372" y="10" id="nunchuk_x"/> <mx:Text x="536" y="10" text="IR p"/> <mx:Text x="536" y="62" text="IR x"/> <mx:Text x="536" y="88" text="IR y"/> <mx:Text x="536" y="114" text="IR z"/> <mx:Text x="594" y="10" id="ir_p"/> <mx:Text x="594" y="62" id="ir_x"/> <mx:Text x="594" y="88" id="ir_y"/> <mx:Text x="594" y="114" id="ir_z"/> <mx:Text x="536" y="36" text="IR size"/> <mx:Text x="594" y="36" id="ir_size"/> <mx:Text x="373" y="166" id="nunchuk_stick_x"/> <mx:Text x="373" y="192" id="nunchuk_stick_y"/> <mx:Text x="372" y="36" id="nunchuk_y"/> <mx:Text x="372" y="62" id="nunchuk_z"/> <mx:Text x="273" y="36" text="nunchuk y"/> <mx:Text x="273" y="62" text="nunchuk z"/> <mx:Text x="10" y="62" text="wiimote z"/> <mx:Text x="110" y="10" id="wiimote_x"/> <mx:Text x="110" y="62" id="wiimote_z"/> <mx:Text x="10" y="88" text="wiimote yaw"/> <mx:Text x="10" y="140" text="wiimote pitch"/> <mx:Text x="10" y="166" text="wiimote A"/> <mx:Text x="10" y="192" text="wiimote B"/> <mx:Text x="10" y="296" text="wiimote +"/> <mx:Text x="10" y="400" text="wiimote right"/> <mx:Text x="10" y="426" text="wiimote home"/> <mx:Text x="110" y="168" id="wiimote_A"/> <mx:Text x="110" y="194" id="wiimote_B"/> <mx:Text x="110" y="298" id="wiimote_plus"/> <mx:Text x="110" y="402" id="wiimote_right"/> <mx:Text x="110" y="428" id="wiimote_home"/> <mx:Text x="110" y="376" id="wiimote_left"/> <mx:Text x="110" y="350" id="wiimote_down"/> <mx:Text x="110" y="324" id="wiimote_up"/> <mx:Text x="110" y="272" id="wiimote_minus"/> <mx:Text x="110" y="246" id="wiimote_2"/> <mx:Text x="110" y="220" id="wiimote_1"/> <mx:Text x="10" y="374" text="wiimote left"/> <mx:Text x="10" y="348" text="wiimote down"/> <mx:Text x="10" y="322" text="wiimote up"/> <mx:Text x="10" y="270" text="wiimote -"/> <mx:Text x="10" y="244" text="wiimote 2"/> <mx:Text x="10" y="218" text="wiimote 1"/> <mx:Text x="110" y="88" id="wiimote_yaw"/> <mx:Text x="110" y="140" id="wiimote_pitch"/> <mx:Text x="110" y="114" id="wiimote_roll"/> <mx:Text x="10" y="114" text="wiimote roll"/> <mx:Text x="110" y="36" id="wiimote_y"/> <mx:Text x="10" y="36" text="wiimote y"/> </mx:WindowedApplication>
<p>EdBrowserもwiimote対応中だよ。</p>
<h4> 参考サイトだよ</h4>
<ul>
<li><a href="http://cs3book.flashoop.jp/wiki/index.php?Wii%E3%83%AA%E3%83%A2%E3%82%B3%E3%83%B3%E3%81%A8AS3" target="_blank">WiiリモコンとAS3 - Flash OOP Japan</a></li>
</ul>
</div>
COMMENT: AUTHOR: takason DATE: 10/24/2008 20:56:48 おぉ、すばらしい!!