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—adding an Actor to the game

Now, we are going to add the UFO as an actor to our existing game, with a predefined behavior:

  1. Stay in the 3DInvadersSilverlight project.
  2. Open InvadersGame.cs.
  3. Add the following private variable in the public class InvadersGame : RealTimeGame, to hold the new Ufo instance:
    private Ufo _ufo1;
    
  4. Add the following lines of code before the end of the Initialize method to create an Ufo instance and add this actor to the game:
    _ufo1 = new Ufo(this, Scene);
    AddActor(_ufo1);
    
  5. Build and run the solution. The default web browser will appear displaying the two spaceships, and an UFO made of bricks moving through the 3D space, as shown in the following picture:
  6. Click on the web browser's viewport to activate its focus. Move ...

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