当前位置: 首页>>代码示例>>C#>>正文


C# TileMap.AddTileset方法代码示例

本文整理汇总了C#中TileMap.AddTileset方法的典型用法代码示例。如果您正苦于以下问题:C# TileMap.AddTileset方法的具体用法?C# TileMap.AddTileset怎么用?C# TileMap.AddTileset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TileMap的用法示例。


在下文中一共展示了TileMap.AddTileset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: openLayerToolStripMenuItem_Click

        void openLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofDialog = new OpenFileDialog();
            ofDialog.Filter = "Map Layer Data (*.mldt)|*.mldt";
            ofDialog.CheckPathExists = true;
            ofDialog.CheckFileExists = true;

            DialogResult result = ofDialog.ShowDialog();

            if (result != DialogResult.OK)
                return;

            MapLayerData data = null;

            try
            {
                data = XnaSerializer.Deserialize<MapLayerData>(ofDialog.FileName);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Error reading map layer");
                return;
            }

            for (int i = 0; i < clbLayers.Items.Count; i++)
            {
                if (clbLayers.Items[i].ToString() == data.MapLayerName)
                {
                    MessageBox.Show("Layer by that name already exists.", "Existing layer");
                    return;
                }
            }

            clbLayers.Items.Add(data.MapLayerName, true);

            layers.Add(MapLayer.FromMapLayerData(data));

            if (map == null)
            {
                map = new TileMap(tileSets[0], (MapLayer)layers[0]);

                for (int i = 0; i < tileSets.Count; i++)
                    map.AddTileset(tileSets[i]);
            }
        }
开发者ID:AlanWills,项目名称:Mythology,代码行数:45,代码来源:FormMain.cs

示例2: openLevelToolStripMenuItem_Click

        void openLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofDialog = new OpenFileDialog();
            ofDialog.Filter = "Level Files (*.xml)|*.xml";
            ofDialog.CheckFileExists = true;
            ofDialog.CheckPathExists = true;

            DialogResult result = ofDialog.ShowDialog();

            if (result != DialogResult.OK)
                return;

            string path = Path.GetDirectoryName(ofDialog.FileName);

            LevelData newLevel = null;
            MapData mapData = null;

            try
            {
                newLevel = XnaSerializer.Deserialize<LevelData>(ofDialog.FileName);
                mapData = XnaSerializer.Deserialize<MapData>(path + @"\Maps\" + newLevel.MapName + ".xml");
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Error reading level");
                return;
            }

            tileSetImages.Clear();
            tileSetData.Clear();
            tileSets.Clear();
            layers.Clear();
            lbTileset.Items.Clear();
            clbLayers.Items.Clear();

            levelData = newLevel;

            foreach (TilesetData data in mapData.Tilesets)
            {
                Texture2D texture = null;

                tileSetData.Add(data);
                lbTileset.Items.Add(data.TilesetName);

                GDIImage image = (GDIImage)GDIBitmap.FromFile(data.TilesetImageName);
                tileSetImages.Add(image);

                using (Stream stream = new FileStream(data.TilesetImageName, FileMode.Open, FileAccess.Read))
                {
                    texture = Texture2D.FromStream(GraphicsDevice, stream);
                    tileSets.Add(
                        new Tileset(
                            texture,
                            data.TilesWide,
                            data.TilesHigh,
                            data.TileWidthInPixels,
                            data.TileHeightInPixels));
                }
            }

            foreach (MapLayerData data in mapData.Layers)
            {
                clbLayers.Items.Add(data.MapLayerName, true);
                layers.Add(MapLayer.FromMapLayerData(data));
            }

            lbTileset.SelectedIndex = 0;
            clbLayers.SelectedIndex = 0;
            nudCurrentTile.Value = 0;

            map = new TileMap(tileSets[0], (MapLayer)layers[0]);

            for (int i = 1; i < tileSets.Count; i++)
                map.AddTileset(tileSets[i]);

            for (int i = 1; i < layers.Count; i++)
                map.AddLayer(layers[i]);

            tilesetToolStripMenuItem.Enabled = true;
            mapLayerToolStripMenuItem.Enabled = true;
            charactersToolStripMenuItem.Enabled = true;
            chestsToolStripMenuItem.Enabled = true;
            keysToolStripMenuItem.Enabled = true;
        }
开发者ID:AlanWills,项目名称:Mythology,代码行数:84,代码来源:FormMain.cs

示例3: newLayerToolStripMenuItem_Click

        void newLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (FormNewLayer frmNewLayer = new FormNewLayer(levelData.MapWidth, levelData.MapHeight))
            {
                frmNewLayer.ShowDialog();

                if (frmNewLayer.OKPressed)
                {
                    MapLayerData data = frmNewLayer.MapLayerData;

                    if (clbLayers.Items.Contains(data.MapLayerName))
                    {
                        MessageBox.Show("Layer with name " + data.MapLayerName + " exists.", "Existing layer");
                        return;
                    }

                    MapLayer layer = MapLayer.FromMapLayerData(data);
                    clbLayers.Items.Add(data.MapLayerName, true);
                    clbLayers.SelectedIndex = clbLayers.Items.Count - 1;

                    layers.Add(layer);

                    if (map == null)
                    {
                        map = new TileMap(tileSets[0], (MapLayer)layers[0]);

                        for (int i = 0; i < tileSets.Count; i++)
                            map.AddTileset(tileSets[1]);

                        for (int i = 1; i < layers.Count; i++)
                            map.AddLayer(layers[1]);
                    }

                    charactersToolStripMenuItem.Enabled = true;
                    chestsToolStripMenuItem.Enabled = true;
                    keysToolStripMenuItem.Enabled = true;
                }
            }
        }
开发者ID:AlanWills,项目名称:Mythology,代码行数:39,代码来源:FormMain.cs


注:本文中的TileMap.AddTileset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。