|
imported>Administrator |
1行目: |
1行目: |
− | [[MonoGame]]で[[マウス]]を使用する。
| + | RC AirHogs ローリングファントム |
− | 主に[[MonoGame/クラスライブラリ/Mouseクラス|Mouseクラス]]のGetStateメソッドを使ったサンプル。マウスで「[[ぷにコン]]」みたいのを表示してみる。少し改造して[[MonoGame/クラスライブラリ/TouchPanelクラス| TouchPanelクラス]]に置き換えれば[[Android]]などで[[ぷにコン]]もどきになると思われる。
| |
| | | |
− | このサンプルではC3.MonoGame.Primitives2Dを使用し、その[[MonoGame/クラスライブラリ/SpriteBatchクラス|SpriteBatchクラス]]拡張メソッド群で円や直線の描画を行っている。
| + | ローリングファントムとは子供向けの室内専用ドローンである。 |
− | C3.MonoGame.Primitives2DにNuGetパッケージはないのでGitHubからソースコードをダウンロードして入れよう。
| + | コントローラーと本体の通信が電波ではなく赤外線通信なため野外では使用できない(太陽光の赤外線に負ける)。 |
− | * https://github.com/z2oh/C3.MonoGame.Primitives2D
| |
| | | |
| + | == 概要 == |
| + | * 名称: ローリングファントム |
| + | * 価格: 税込6998円(税抜6480円) |
| + | * 電池: コントローラーは単三電池6本、本体はコントローラーからの電源供給で充電 |
| | | |
− | <source> | + | ドローン本体はローラーフレームで保護されているため壁や天井にぶつかっても安心。 |
− | using System;
| + | むしろゲームでよくある壁走りや天井走りを楽しむドローンとなっている。 |
| + | <movie>https://www.youtube.com/watch?v=-3d_OVSaTsw</movie><br clear="both"/> |
| | | |
− | using Microsoft.Xna.Framework;
| + | * http://www.happinettoys.com/contents/airhog/rolling_phantom/index.html |
− | using Microsoft.Xna.Framework.Graphics;
| |
− | using Microsoft.Xna.Framework.Input;
| |
− | using Microsoft.Xna.Framework.Input.Touch;
| |
| | | |
− | using C3.MonoGame;
| + | == 備考 == |
− | | + | 何度も言うが「室内専用」である。 |
− | namespace MonoGameSamples
| |
− | {
| |
− | public class Game1 : Game
| |
− | {
| |
− | GraphicsDeviceManager graphics;
| |
− | SpriteBatch spriteBatch;
| |
− | Vector2? startPosition = null;
| |
− | Vector2? deltaPosition = null;
| |
− | | |
− | public Game1()
| |
− | {
| |
− | graphics = new GraphicsDeviceManager(this);
| |
− | Content.RootDirectory = "Content";
| |
− | }
| |
− | | |
− | protected override void Initialize()
| |
− | {
| |
− | // マウスカーソルを表示する
| |
− | this.IsMouseVisible = true;
| |
− | | |
− | base.Initialize();
| |
− | }
| |
− | | |
− | protected override void LoadContent()
| |
− | {
| |
− | spriteBatch = new SpriteBatch(GraphicsDevice);
| |
− | }
| |
− | | |
− | protected override void Update(GameTime gameTime)
| |
− | {
| |
− | | |
− | #if !__IOS__ && !__TVOS__
| |
− | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
| |
− | Exit();
| |
− | #endif
| |
− | | |
− | var mouse = Mouse.GetState();
| |
− | if (mouse.LeftButton == ButtonState.Pressed)
| |
− | {
| |
− | if (startPosition == null)
| |
− | {// ドラッグ開始
| |
− | startPosition = mouse.Position.ToVector2();
| |
− | }
| |
− | else
| |
− | {// ドラッグ中
| |
− | deltaPosition = mouse.Position.ToVector2();
| |
− | }
| |
− | }
| |
− | else
| |
− | {
| |
− | startPosition = null;
| |
− | deltaPosition = null;
| |
− | }
| |
− | | |
− | | |
− | base.Update(gameTime);
| |
− | }
| |
− | | |
− | protected override void Draw(GameTime gameTime)
| |
− | {
| |
− | graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
| |
− | | |
− | spriteBatch.Begin();
| |
− | {
| |
− | if (startPosition != null)
| |
− | {// 始点描画
| |
− | spriteBatch.DrawCircle(startPosition.Value, 20, 16, Color.Red);
| |
− | }
| |
− | | |
− | if (deltaPosition != null)
| |
− | {// 現在点描画
| |
− | spriteBatch.DrawLine(startPosition.Value, deltaPosition.Value, Color.White);
| |
− | spriteBatch.DrawCircle(deltaPosition.Value, 20, 16, Color.Red);
| |
− | }
| |
− | }
| |
− | spriteBatch.End();
| |
− | | |
− | base.Draw(gameTime);
| |
− | }
| |
− | }
| |
− | }
| |
− | </source>
| |
| | | |
| == 関連項目 == | | == 関連項目 == |
− | * [[MonoGameでマウスカーソルを表示する]] | + | * [[RC ホバーシャーク]] |
| | | |
− | [[category: MonoGame]] | + | [[category: 玩具]] |