Time for action - fixing the scrolling delay

  1. Reopen the Design mode view of the MapEditor window.
  2. Double-click on the Timer control in the Toolbox window to add a new instance to the MapEditor form. As with the ImageList control, the Timer is not visible, and will appear in the editor as an icon and label below the design window. Give the timer control the following properties:
    • Name : timerGameUpdate
    • Enabled : True
    • Interval : 20
  3. Double-click on the timerGameUpdate control to generate a Tick event handler and add the following code to it:
    private void timerGameUpdate_Tick(object sender, EventArgs e)
    {
    if (hScrollBar1.Maximum < 0)
    {
    FixScrollBarScales();
    }
    game.Tick();
    if (game.HoverCodeValue != lblCurrentCode.Text)
    lblCurrentCode.Text = game.HoverCodeValue;
    }
    
  4. Execute the application. Draw a few tiles on the map and use the scroll bars to verify that they function as expected.

What just happened?

Using the scroll bars does not prevent the Timer control from firing its Tick event, so by executing the game's Tick() method from within the timerGameUpdate_Tick() event handler, we can force the game's Update() and Draw() methods to run even when they normally would not.

The last item in the timerGameUpdate_Tick() handler checks to see if the HoverCodeValue inside the Game1 class has been updated since it was last copied to the label displaying it on the Windows Form. If it has, the form label is updated as well.

Loading and Saving Maps

The last thing we need to address to complete the Gemstone Hunter Level Editor is how we will load and save our map files. There are a number of ways we could store our level maps, but we will implement a very simple method that does not require parsing XML or creating a text file with a special format to store the map.

..................Content has been hidden....................

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