PositionedObject
Last updated
Was this helpful?
Last updated
Was this helpful?
The PositionedObject is an object which contains properties and functionality for position, rotation, attachment, velocity, acceleration, and instructions. It serves as the base object for common FlatRedBall classes such as the , , and objects. The PositionedObject is also the base class of .
PositionedObject-Inheriting Class
Associated Manager
FlatRedBall.PositionedObject
Absolute position can be directly controlled through the X, Y, and Z properties as well as the exposed Position field. The following code creates three with various positions. Note that the default position of a PositionedObject is (0,0,0). Also, note that in the screenshot below, the Z value impacts the size of sprite3 , implying that the game is using a 3D Camera.
The default view in FlatRedBall is down the Z axis using a perspective view. Therefore modifying the Z value of PositionedObjects can result in apparent changes in size. FlatRedBall MDX uses a left-handed coordinate system while FlatRedBall XNA uses a right-handed coordinate system. This means that the Z axes point the opposite direction on each version, so keep this in mind if switching from one to the other. By default, positive Z moves objects further away from the camera in FlatRedBall MDX. Positive Z moves objects closer to the camera in FlatRedBall XNA.
The SpriteManager can also perform common management on PositionedObjects. Therefore, adding the following line will result in the object being managed by the SpriteManager and exhibiting all expected behavior:
To remove an object that has been added this way from management, call:
Since the Position and X/Y/Z properties are all part of the PositionedObject class, any class that inherits from the PositionedObject class (list can be viewed above in the table) has these properties. In other words, the code above uses , but it could have used any PositionedObject-inheriting object to achieve the same results.
Velocity represents the speed at which an object is moving. Mathematically, it represents the change in position measured in units per second. While the PositionedObject itself does not apply velocity automatically, any PositionedObject-inheriting instance which is created through or added to FlatRedBall managers will have its velocity automatically applied to its position. This is the case for , , and objects. Similarly, Acceleration modifies velocity on all objects which belong to FlatRedBall managers. It represents the rate of change of velocity in units per second. Acceleration is often used to simulate forces applied to an object such as gravity or a rocket's thrust. The following code creates two Polygons. One moves to the left while the other begins moving up and to the right, but falls downward as if affected by gravity. Although the section covering position used Sprites, this section uses Polygons to show that the same code works on many FlatRedBall types.
For more information on Velocity, see the . For more information on Acceleration, see the .
See the .
PositionedObjects implement the IAttachable interface. For more information on attachments and the IAttachable interface, see the entry.
PositionedObjects implement the interface allowing them to store and execute instructions. Most PositionedObjects such as and objects have their instructions executed automatically by their corresponding managers. For more information, see the page.
Most PositionedObjects like and are managed by managers as listed above. However, it is common practice to create objects which inherit from PositionedObjects. When one of these objects is instantiated it is not automatically managed, therefore fields like Velocity and Acceleration are not applied. In other words, the following code will NOT result in an object that moves across the screen: