Time for action - scroll bars

  1. In the Toolbox window, double-click on the VScrollBar control to add it to the form. Give it the following properties:

    a. Name : vScrollBar1

    b. Anchor : Top, Bottom, Right

    c. LargeChange : 48

    d. Location : 658, 27

    e. Size : 17, 576

  2. In the Toolbox window, double-click on the HScrollBar control to add it to the form. Give it the following properties:

    a. Name : hScrollBar1

    b. Anchor : Bottom, Left, Right

    c. LargeChange : 48

    d. Location : 184, 606

    e. Size : 474, 17

  3. Add the FixScrollBarScales() helper method to the MapEditor class:
    private void FixScrollBarScales()
    {
    Camera.ViewPortWidth = pctSurface.Width;
    Camera.ViewPortHeight = pctSurface.Height;
    Camera.Move(Vector2.Zero);
    vScrollBar1.Minimum = 0;
    vScrollBar1.Maximum =
    Camera.WorldRectangle.Height -
    Camera.ViewPortHeight;
    hScrollBar1.Minimum = 0;
    hScrollBar1.Maximum =
    Camera.WorldRectangle.Width -
    Camera.ViewPortWidth;
    }
    
  4. Edit the MapEditor_Load() method to include a call to FixScrollBarScales():
    FixScrollBarScales():
    FixScrollBarScales();
    
  5. Double-click on MapEditor.cs in SolutionExplorer to reopen the Design mode view of the MapEditor form.
  6. Click on the title bar of the MapEditor window to select the form as the active control.
  7. In the Properties window, ensure that the drop-down box at the top of the window reads MapEditor System.Windows.Forms.Form.
  8. Still in the Properties widow, click on the yellow lightning bolt button in the toolbar to switch the view from properties to event handlers:
    Time for action - scroll bars
  9. Scroll down and locate the Resize event and double-click on the empty box to the right of the event name, causing C# to automatically generate an event handler for the MapEditor_Resize event.
  10. Add the following to the MapEditor_Resize() method:
  11. Switch back to properties view in the Properties window by going back to the Design mode view of the form and clicking on the small page icon to the left of the lightning bolt icon in the Properties window toolbar.

What just happened?

We now have scroll bars attached to the sides of the game's display area. When the form is initially displayed, and then again whenever it is resized, the scroll bars will be rescaled so that they cover the entire area of the game's tile map.

We will use these scroll bars to move around on the map while editing, though their actual implementation will again be tied to changes to the Game1 class.

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

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