IInstructable
Introduction
Using Instructions
// Add this using statement
using FlatRedBall.Instructions;
// Declare the Sprite instance at class scope
Sprite sprite;
// Replace Initialize with the following:
protected override void Initialize()
{
FlatRedBallServices.InitializeFlatRedBall(this, this.graphics);
base.Initialize();
sprite = SpriteManager.AddSprite("redball.bmp");
}
// Replace Update with the following.
protected override void Update(GameTime gameTime)
{
FlatRedBallServices.Update(gameTime);
if (InputManager.Keyboard.KeyPushed(Keys.Space) &&
sprite.Instructions.Count == 0)
{
float secondsToTake = 4.0f;
float squareWidth = 10;
float velocity = squareWidth * 4.0f / secondsToTake;
// Move right.
sprite.Instructions.Add(
new Instruction<Sprite, float>(
sprite, "XVelocity", velocity,
TimeManager.CurrentTime + 0));
// Stop moving to the right.
sprite.Instructions.Add(
new Instruction<Sprite, float>(
sprite, "XVelocity", 0,
TimeManager.CurrentTime + secondsToTake / 4.0f));
// Move down.
sprite.Instructions.Add(
new Instruction<Sprite, float>(
sprite, "YVelocity", -velocity,
TimeManager.CurrentTime + secondsToTake / 4.0f));
// Stop moving down.
sprite.Instructions.Add(
new Instruction<Sprite, float>(
sprite, "YVelocity", 0,
TimeManager.CurrentTime + 2 * secondsToTake / 4.0f));
// Move left.
sprite.Instructions.Add(
new Instruction<Sprite, float>(
sprite, "XVelocity", -velocity,
TimeManager.CurrentTime + 2 * secondsToTake / 4.0f));
// Stop moving left;
sprite.Instructions.Add(
new Instruction<Sprite, float>(
sprite, "XVelocity", 0,
TimeManager.CurrentTime + 3 * secondsToTake / 4.0f));
// Move up.
sprite.Instructions.Add(
new Instruction<Sprite, float>(
sprite, "YVelocity", velocity,
TimeManager.CurrentTime + 3 * secondsToTake / 4.0f));
// Stop moving up at the end.
sprite.Instructions.Add(
new Instruction<Sprite, float>(
sprite, "YVelocity", 0,
TimeManager.CurrentTime + 4 * secondsToTake / 4.0f));
}
base.Update(gameTime);
}Calling instructions on the object that will be modified
InstructionManager
IInstructable Members
Last updated
Was this helpful?