Пример #1
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            AntsX.TMXTiledMap.map m = loadTMXMapFromFile(@"H:\XNAGame\content\unbenannt.xml");
            createMapFromTMXMap(m);

            initViewport();

            this.inputService = (IInputService)this.Game.Services.GetService(typeof(IInputService));

            base.Initialize();
        }
Пример #2
0
        private void createMapFromTMXMap(AntsX.TMXTiledMap.map tmxmap)
        {
            this.Width       = tmxmap.width;
            this.Height      = tmxmap.height;
            this.TileHeight  = tmxmap.tileheight;
            this.TileWidth   = tmxmap.tilewidth;
            this.PixelWidth  = this.Width * this.TileWidth;
            this.PixelHeight = this.Height * this.TileHeight;

            this.map = new MapNode[this.Height, this.Width];

            foreach (layer l in tmxmap.Items)
            {
                switch (l.name)
                {
                case "ground":
                    if (l.width != this.Width || l.height != this.Height)
                    {
                        throw new ArgumentException("layer has not the same size");
                    }

                    int y = 0, x = 0;
                    foreach (layerDataTile dataTile in l.data.Items)
                    {
                        if (x == this.map.GetLength(0))
                        {
                            x = 0;
                            y++;
                        }


                        this.map[y, x] = new MapNode()
                        {
                            TileImage    = this.Game.Content.Load <Texture2D>(@".\map\tiles\ground32"),
                            TilePosition = new Vector2(x * this.TileWidth, y * this.TileHeight)
                        };

                        x++;
                    }

                    break;

                default: throw new ArgumentException("unknown layer type");
                }
            }
        }