Time for action - handling the FormClosed event

  1. Open the MapEditor form in Design mode.
  2. Select the form as the current object by clicking on the form's title bar in the Design window.
  3. Switch to Event editing mode in the Properties window by clicking on the lightning-bolt button.
  4. Scroll down to the FormClosed event and double-click in the empty box to the right of the event name to create the MapEditor_FormClosed() event handler.
  5. Update the event handler to read:
    private void MapEditor_FormClosed(
    object sender,
    FormClosedEventArgs e)
    {
    game.Exit();
    Application.Exit();
    }
    

What just happened?

When the form closes, we need to shut down both the XNA game and the overall application, otherwise the system will not release the resources, and the program will still be running invisibly in the background.

Have a go hero -

The Gemstone Hunter Level Editor project is fairly rough around the edges. It is not exactly a model example of Windows Forms development, but then few purpose-built internal game development tools are.

If you feel like diving further into Windows Forms development, here are a few suggestions for improving on the level editor:

  • Currently, the level editor does not alert you if you try to load a map after you have made changes to the current map. By adding checks to the Update() method of the Game1 class, you could flag the map as having changed and issue the appropriate warnings to the user when they try to load a new map.
  • Marking squares as impassable requires an individual click on each square. You could expand the number of radio buttons to include marking squares as passable and impassable as separate tasks, thus allowing the user to hold down the mouse button and draw large blocks of impassable squares.
  • On the more game-focused side of things, try creating a few levels! The level editor supports up to 100 levels (000 through 099), so there is plenty of room to experiment.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.78.106