O'Reilly logo

3D Game Development with Microsoft Silverlight 3 Beginner's Guide by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—programming the input control in the game loop

Now, it is time to make the necessary changes to the game loop in order to use our new keyboard manager:

  1. Stay in the SilverlightInvaders2DVector project.
  2. Open the code for the superclass SpriteWrapper.
  3. Replace the public methods GoUp, GoDown, GoLeft, and GoRight with the following public methods to allow each key to change the speed for an independent axis:
    public void GoUp()
    {
    _speed.Y = -_incrementY;
    //_speed.X = 0;
    }
    public void GoDown()
    {
    _speed.Y = _incrementY;
    //_speed.X = 0;
    }
    public void GoLeft()
    {
    _speed.X = -_incrementX;
    //_speed.Y = 0;
    }
    public void GoRight()
    {
    _speed.X = _incrementX;
    //_speed.Y = 0;
    }
    

    Note

    We just commented the lines that assigned a 0 to the axis that did not ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required