The MoveToAccurate creates a set of Instructions for moving a PositionedObject to a given point in a set amount of time.

Code Example

The following code moves a Sprite to the position where the user clicks the Mouse. Note that this could be implemented with any PositionedObject, including any Glue entity. Add the following using statements to your Glue screen:

using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.Instructions;

Add the following to your screen's CustomInitialize to show the mouse:

 // to show the cursor
 IsMouseVisible = true;

Add the following to your Screen's CustomActivity, assuming SpriteInstance is a Sprite in your Screen:

 void CustomActivity()
     // The number of seconds to take to move to where the user
     // clicks.
     float secondsToTake = 2;

     // A button release is a "click".
     // Don't create new movement instructions if there are
     // already other movement instructions - things can get wacky.
     if (InputManager.Mouse.ButtonReleased(
             FlatRedBall.Input.Mouse.MouseButtons.LeftButton) &&
         SpriteInstance.Instructions.Count == 0)
         // We could create the Instructions ourselves, but the
         // InstructionManager makes things easy.

Last updated