KeepTrackOfReal
Introduction
The PositionedObject's Velocity and Acceleration values often dictate the position and movement of a PositionedObject, but sometimes these properties are also used in game code to control other objects. For example, in a physically realistic game if an airplane is flying at a certain speed and fires a bullet, the bullet's world velocity should equal the velocity relative to the barrel where it was fired plus the velocity of the airplane (at least initially if drag is being considered). In these situations it's important to use the accurate velocity or acceleration; but sometimes the value reported in the Velocity and Acceleration properties do not reflect the actual on-screen velocity of an object. For example, if we made a game where our character was standing on a boat, we may simply attach the character to the boat and work with relative positions. If the boat moves, the character moves, but we never explicitly set the character's Velocity property, nor has the engine touched it. If we want to base behavior off of the character's actual world velocity then we can use "real" values. To use real values, the KeepTrackOfReal property must be set to true. After this is done, any PositionedObject which is being managed will report its real velocity and acceleration through its RealVelocity and RealAcceleration properties.
Code Example
The following code creates two Sprites and uses the RealVelocity property of the attached Sprite to apply a velocity to newly-created Sprites. In Initialize after initializing FlatRedBall:
Later define CreateNewSpriteEachFrame:
Last updated