YouTube | Facebook | X(Twitter) | RSS

GraphicTracker を使用したRPG風シンボルの移動

2013/8/22 (木)

MapControl に GraphicTracker を使用してシンボルを移動するサンプルです。ほんとはアドルでやりたかったんだけど Ys PC-9801 版な画像が見つからなかったので Sa・Ga おとこ でやってみました。しかも移動はドラクエⅠ風です(前しか向きません)。

残念ながら戦闘モードには入りません。そのため、「かみはばらばらになった」も再現できません。あくまでもお昼休みに作ったサンプルです。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.EngineCore;

namespace MappingApplication_CS
{
    public partial class Form1 : Form
    {
        double g_X;
        double g_Y;

        IGraphicTracker g_pGraphicTracker;
        IGraphicTrackerSymbol g_pGraphicTrackerSymbol1;
        IGraphicTrackerSymbol g_pGraphicTrackerSymbol2;
        int g_ID;
        bool g_Flag;

        public Form1()
        {
            InitializeComponent();

            //GraphicTrackerの初期化
            g_pGraphicTracker = new GraphicTrackerClass();
            g_pGraphicTracker.Initialize(axMapControl1.Map as IBasicMap);

            string path = @".\saga.png";
            string path2 = @".\saga2.png";

            g_pGraphicTrackerSymbol1 = g_pGraphicTracker.CreateSymbolFromPath(path, path);
            g_pGraphicTrackerSymbol2 = g_pGraphicTracker.CreateSymbolFromPath(path2, path2);
            
            IPoint pPoint = new PointClass();
            pPoint.PutCoords(0, 0);
            g_X = 1278000;
            g_Y = 341000;
            g_ID = g_pGraphicTracker.Add(pPoint as IGeometry, g_pGraphicTrackerSymbol1);
            g_pGraphicTracker.SetOrientationMode(g_ID, esriGTOrientation.esriGTOrientationFixed);

            //Timerイベント
            Timer timer = new Timer();
            timer.Interval = 1000;
            timer.Tick += new EventHandler(timer1_Tick);
            timer.Start();
        }


        //現在のマウスカーソル位置の座標をステータスバーに表示する
        private void axMapControl1_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
        {
            string x = System.Convert.ToString(e.mapX);
            string y = System.Convert.ToString(e.mapY);
            toolStripStatusLabel1.Text = "X: " + x + "  " + "Y: " + y;
        }

        //タイマー イベント ハンドラ
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (g_Flag == true)
            {
                g_pGraphicTracker.SetSymbol(0, g_pGraphicTrackerSymbol1);
                g_Flag = !g_Flag;
            }
            else
            {
                g_pGraphicTracker.SetSymbol(0, g_pGraphicTrackerSymbol2);
                g_Flag = !g_Flag;
            }

            g_pGraphicTracker.MoveTo(g_ID, g_X, g_Y, 0.0);

        }

        private void axMapControl1_OnKeyDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnKeyDownEvent e)
        {
            switch (e.keyCode)
            {
                //8キー
                case (int)104:
                    g_Y += 50;
                    break;

                //2キー
                case (int)98:
                    g_Y -= 50;
                    break;
                //4キー
                case (int)100:
                    g_X -= 50;
                    break;

                //6キー
                case (int)102:
                    g_X += 50;
                    break;
            }
        }
    }
}

関連記事

  • この記事を書いた人

羽田 康祐

伊達と酔狂のGISエンジニア。GIS上級技術者、Esri認定インストラクター、CompTIA CTT+ Classroom Trainer、潜水士、PADIダイブマスター、四アマ。WordPress は 2.1 からのユーザーで歴だけは長い。 代表著書『地図リテラシー入門―地図の正しい読み方・描き方がわかる』 GIS を使った自己紹介はこちら。ESRIジャパン(株)所属、元青山学院大学非常勤講師を兼務。日本地図学会第31期常任委員。発言は個人の見解です。

-プログラミング, ArcGIS
-,

WINGFIELD since1981をもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む