This project is read-only.
Tutorial 3.2: Moving Actors Based On Input
In this tutorial, we will move our ship based on arrow key presses. To do so we will add the following code to our Update() method, before XE2.Update():

if (XInput.Device(1).KBState(1).IsKeyDown(Keys.Up))
        XScene.Actor("ShipActor").Rotation.X += .75f;
if (XInput.Device(1).KBState(1).IsKeyDown(Keys.Down))
        XScene.Actor("ShipActor").Rotation.X -= .75f;
if (XInput.Device(1).KBState(1).IsKeyDown(Keys.Left))
        XScene.Actor("ShipActor").Rotation.Y -= .75f;
if (XInput.Device(1).KBState(1).IsKeyDown(Keys.Right))
        XScene.Actor("ShipActor").Rotation.Y += .75f;

Now, your model should rotate when you press the arrow keys.


Congratulations, your game can now use the keyboard for input. You can download the source for this project here:

Last edited Mar 23, 2008 at 8:26 AM by Hazardous101, version 5


No comments yet.