Gum uses a different coordinate system compared to FlatRedBall. The separate Gum coordinate system exists for two reasons:
Gum objects are often positioned relative to the screen bounds rather than world coordinates. For example, a HUD should always appear at the top-left of the screen.
Gum objects may use different coordinate units. For example, a "Join Game" callout may be positioned 25% from the left edge of the screen rather than using pixel coordinates.
At times games may need to position FlatRedBall objects (such as entities) relative to the position of a Gum object. This document explains how to convert Gum to FlatRedBall coordinates.
Note that it is possible to add Gum components to FlatRedBall entities, and doing so results in the components being drawn in world coordinates (FRB coordinates). Adding a Gum component to a FlatRedBall Entity is the easiest way to position a Gum object in world space. For more information see the Components in FlatRedBall Entities page.
Gum objects which have no parents and which are using absolute X and Y coordinates are already in screen coordinates. Of course, most Gum objects are nested inside other parent Gum objects, and they may be using other X and Y units.
The following code shows how to display the four edge bounds for a ColoredRectangleInstance:
The high level steps for converting from Gum to FlatRedBall coordinates are:
Convert the Gum coordinates to screen coordinates - coordinates relative to the top-left of the screen
Convert the screen coordinates to world coordinates - the coordinates used by FlatRedBall objects
(Optional) position the FlatRedBall object using the world coordinates.
For this example, consider a Gum screen with a single colored rectangle named ColoredRectangleInstance:
Note that the rectangle is positioned according to its center. This example will position a FlatRedBall Circle named CircleInstance. Note that this code can be used to position any FlatRedBall positioned object (such as entities or other collision shapes).
The following code can be used to convert the rectangle's position (which in this case is the center) to screen coordinates:
Notice that the example above uses the position of the ColoredRectangleInstance as defined by its XOrigin and YOrigin. If the rectangle's origin is changed to top-right in Gum...
...then the FlatRedBall CircleInstance will also be positioned on the Gum object's top-right corner.
The high level steps for converting from FlatRedBall to Gum coordinates are:
Convert the FlatRedBall coordinates to Screen pixel coordinates
Convert the screen pixel coordinates to Gum screen coordinates (considering zooming)
(Optional) Position a Gum object using the Gum screen coordinates
The following code creates colored rectangle instances on clicks. Notice that the Cursor's world coordinates are used to get the Gum coordinates: