こんにちは!倉本です.
enchant.jsについて紹介しようかと思ったのですが,
西崎君に先を越されたのでwiiリモコンのJavaScriptについて書きます!
wiiインターネットチャンネルでは,特別なオブジェクトを用いるだけで,
wiiリモコンのひねりやセンサーバーとの距離を簡単に取得できます.
window.opera.wiiremote オブジェクト
これがwiiリモコンのプロパティを保持したオブジェクトになります.
このオブジェクトのupdate(num)というメソッドを呼び出すことで
リモコンの状態を保持したオブジェクトが返ってきます.
numはプレイヤーの番号で,0~3の数字を指定します.
オブジェクトのプロパティは以下の一覧の通りです.
プロパティ | 説明 |
---|---|
isEnabled | wiiリモコンが接続されている場合,1. |
isDataValid | データが有効な場合,1. |
isBrowsing | ブラウジングしているwiiリモコンの場合,1 |
dpdX dpdY |
ポインティング位置. |
hold | ボタンを押している間,対応したボタンのフラグが立つ. ※ブラウジングしているwiiリモコン(isBrowsing が1であるwiiリモコン)は Bボタンのみ取得できる. |
dpdRollX dpdRollY |
カーソルの傾き方向ベクトル. ベクトルの長さは 1 ,右下がプラス方向. |
dpdDistance | センサーバーとwiiリモコンの距離.遠いほど大きい値になる. |
dpdValidity | ポインティング位置を認識するために用いたオブジェクトの個数. |
それでは,実際に使ってみるために以下のようにJavaScriptをかいてみました.
(function(){ var defaultDistance = 0; $(document).ready(function(){ setInterval('UpdateWiiRemote()', 100); }); function UpdateWiiRemote(){ var pad = opera.wiiremote.update(0); if (pad.isEnabled && pad.isDataValid){ if(defaultDistance == 0){ defaultDistance = round2(pad.dpdDistance); } if(round2(rad * 180 / Math.PI) >= 45){ $("#action").html("右!"); } else if(-45 >= round2(rad * 180 / Math.PI)){ $("#action").html("左!"); } else if(defaultDistance-0.2 >= round2(pad.dpdDistance)){ $("#action").html("前!"); } else if(round2(pad.dpdDistance) >= defaultDistance+0.15){ $("#action").html("後!"); } else{ $("#action").html("ストップ"); } } else{ $("#action").html("未接続"); } } function round2(v){ return Math.round(v*100)/100; } })();
簡単に解説しますと,
・opera.wiiremote.update(0)で1Pのwiiリモコンの情報取得.
・isEnabledとisDataValidでwiiリモコンが接続されていて,データが有効か確認.
・有効であった場合,そのプロパティに応じてアクションを判定.
以上をsetIntervalでまわします.
アクションついて,
傾きは左右どちらかに45度以上傾いているかどうかで判断します.
距離は最初に1度,デフォルト距離としてセンサーバーとwiiリモコンの距離を保持しておき,それと現在の距離を比べて判断します.
こんな感じで傾きと距離の判定を活かして,アクションゲームっぽいのが作れそうですね!
誰かやってみてください!(他力本願)
お粗末な内容でしたが最後まで読んでくれた方,ありがとうございました.
I was able to think a lot while looking at this post. I will pass this blog to many people. Definitely a good blog is very good. Thank you for sharing. Feel free to visit my website; 일본야동
返信削除Attractive portion of content. I simply stumbled upon your website and in accession capital to claim that I get in fact loved account your blog post Feel free to visit my website;
返信削除국산야동
Your style is really unique compared to other people I have read stuff from. I appreciate you for posting when you have the opportunity, Guess I’ll just book mark this site. Feel free to visit my website; 일본야동
返信削除Its blog give information from another people very well I am impress its information an information is very nice. Feel free to visit my website;
返信削除한국야동
Nice Blog. Thanks for sharing with us. Such amazing information.
返信削除How visual content helps to advertise without investing money
Do You have Problem Regarding Destiny Credit Card Login? If you’re looking to check your Desti status, read this post.
返信削除Visit My Post: Destiny Credit Card Login
Once you sign up at Spin Casino, have the ability to|you possibly can} select from 500 titles, major slots with exciting graphics and audio, properly as|in addition to} some incredible options similar to bonus video games, free spins, and Wilds. To take advantage of|benefit from|reap the advantages of} every little thing Spin Casino has to supply, you need to|you 토토사이트 must} be a registered player since playing in} for actual cash isn't potential for visitor customers. The Canadian market is full of with|is stuffed with} sites providing on line casino video games.
返信削除site raja slot88 rtp having the highest slot rtp is much easier for you to make profits and wins easily. the king slot88 rtp site often gives special surprises that will bring you to the peak of victory in playing online slot games
返信削除You have described the JavaScript for the Wii Remote very well! But I still want to invite you to try 1 dollar deposit casino New Zealand, because it is an indispensable service with an interesting interface and offers.
返信削除