Section 5

Larger Margin Around Game Morph

You may have noticed that trying to move the LaserGame morph can be difficult if the only visible areas are the game board morph itself. Clicking on the game board morph causes it to act on the mouse clicks. It does not pick up the morph and grab it for overall movement. An easy way to fix that is make the margin around the outside of our morph a little larger. This way the user can grab it ant any edge to move it.

While we're making this little tweak we will also make a minor cosmetic change to the control panel. All the code changes we will make will be on the LaserGame class.

The first simple change to make is enlarge the margin. Modify the method as follows.

gameMargin
     ^10

If this was all we did there would be a problem with the "laser home" visual we created earlier in this tutorial. The problem is that when we specified the position of the laser home visual we just assumed it would always go to the bottom edge of the overall LaserGame morph. When the margin gets substantially larger, like now, that assumption is no longer useful. Modify the #setupMorphs method to account for this.

setupMorphs
    self layoutPolicy: ProportionalLayout new.
    self setWindowColors.
    self
        addMorph: self makeControlPanelMorph
        fullFrame: (LayoutFrame
                fractions: (0 @ 0 corner: 0 @ 1)
                offsets: (self gameMargin @ self gameMargin
                    corner: (self gameMargin + self panelWidth) @ self gameMargin negated)).
    self
        addMorph: self makeGameBoardMorph
        fullFrame: (LayoutFrame
                fractions: (0 @ 0 corner: 1 @ 1)
                offsets: ((self gameMargin + self panelWidth) @ self gameMargin
                    corner: self gameMargin negated @ self gameMargin negated)).
    self
        addMorph: self makeLaserHomeMorph
        fullFrame: (LayoutFrame
                fractions: (0 @ 1 corner: 0 @ 1)
                offsets: ((self gameMargin + self panelWidth + 1)@(self gameMargin negated)
                    corner: (self gameMargin + self panelWidth + CellRenderer cellExtent x - 2)@(self gameMargin negated + 4))).

Index Page Next Page

Copyright © 2007, 2008, 2009, 2010 Stephan B Wessels    stevewessels@me.com