Beispiel #1
0
 public static Tileset Create(TilesetData data, Game game)
 {
     // assumption is that game's content contains a subdir with all of our tilesets
     var contentString = Path.Combine(TilesetContentSubdir, Path.GetFileNameWithoutExtension(data.TilesetImageName));
     var texture = game.Content.Load<Texture2D>(contentString);
     return new Tileset(texture,
                         data.TilesWide,
                         data.TilesHigh,
                         data.TileWidthInPixels,
                         data.TileHeightInPixels);
 }
Beispiel #2
0
        void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbTilesetName.Text))
            {
                MessageBox.Show("You must enter a name for the tileset.");
                return;
            }

            if (string.IsNullOrEmpty(tbTilesetImage.Text))
            {
                MessageBox.Show("You must select an image for the tileset.");
                return;
            }

            int tileWidth = 0;
            int tileHeight = 0;
            int tilesWide = 0;
            int tilesHigh = 0;

            if (!int.TryParse(mtbTileWidth.Text, out tileWidth))
            {
                MessageBox.Show("Tile width must be an integer value.");
                return;
            }
            else if (tileWidth < 1)
            {
                MessageBox.Show("Tile width must me greater than zero.");
                return;
            }

            if (!int.TryParse(mtbTileHeight.Text, out tileHeight))
            {
                MessageBox.Show("Tile height must be an integer value.");
                return;
            }
            else if (tileHeight < 1)
            {
                MessageBox.Show("Tile height must be greater than zero.");
                return;
            }

            Image tileSet = (Image)Bitmap.FromFile(tbTilesetImage.Text);

            tilesWide = tileSet.Width / tileWidth;
            tilesHigh = tileSet.Height / tileHeight;

            tilesetData = new TilesetData();

            tilesetData.TilesetName = tbTilesetName.Text;
            tilesetData.TilesetImageName = tbTilesetImage.Text;
            tilesetData.TileWidthInPixels = tileWidth;
            tilesetData.TileHeightInPixels = tileHeight;
            tilesetData.TilesWide = tilesWide;
            tilesetData.TilesHigh = tilesHigh;

            okPressed = true;
            this.Close();
        }