Game1.cs
file in the Level Editor project to open it in the editor.public int DrawLayer = 0; public int DrawTile = 0; public bool EditingCode = false; public string CurrentCodeValue = ""; public string HoverCodeValue = ""; public MouseState lastMouseState; System.Windows.Forms.VScrollBar vscroll; System.Windows.Forms.HScrollBar hscroll;
vscroll = (System.Windows.Forms.VScrollBar)parentForm.Controls[ "vScrollBar1"]; hscroll = (System.Windows.FOrms.HScrolLBar)parentForm.Controls[ "hScrollBar1"];
LoadContent()
method of the Game1 class to read:protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); Camera.ViewPortWidth = pictureBox.Width; Camera.ViewPortHeight = pictureBox.Height; Camera.WorldRectangle = new Rectangle( 0, 0, TileMap.TileWidth * TileMap.MapWidth, TileMap.TileHeight * TileMap.MapHeight ); TileMap.Initialize( Content.Load<Texture2D>(@"TexturesPlatformTiles")); TileMap.spriteFont = Content.Load<SpriteFont>(@"FontsPericles8"); lastMouseState = Mouse.GetState(); pictureBox_SizeChanged(null, null); }
Draw()
method of the Game1 class to read:protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin( SpriteSortMode.BackToFront, BlendState.AlphaBlend); TileMap.Draw(spriteBatch); spriteBatch.End(); base.Draw(gameTime); }
To simplify communications between the Windows Form and the XNA Game, we have declared a number of public member variables that our Windows Form code will be able to update in response to user-generated events. We have also loaded a SpriteFont
to draw code values with, and a MouseState
variable to hold the state of the mouse between frames.
Finally, we declare two objects that reference the scroll bars on the level editor form. We will use these to sync up the display of the tile map to the location of the scroll bars.
The LoadContent()
method is fairly standard, setting the size of the tile map, and loading the tile images and sprite font. The TileMap class's spriteFont
member is set to the font we loaded, and the lastMouseState
member is initialized. Right before exiting, the LoadContent()
method calls pictureBox_SizeChanged()
to make sure that the graphics device has the proper dimensions for the display window.
In our Draw()
method, we have again used the expanded form of the SpriteBatch.Begin()
call in order to specify the SpriteSortMode.BackToFront
parameter.
3.138.105.124