WorldYAt

Introduction

The WorldXAt and WorldYAt methods are useful for finding the absolute world position of the Cursor at a given Z value. These methods should generally be used only when dealing with an unrotated Camera. For more information on limitations see below.

If you are dealing with a 2D Camera (the default) then you can use a Z value of 0 in the WorldXAt and WorldYAt functions.

Code Example

The following code creates a Circle which moves with the Cursor.

Add the following using statements:
Add the following at class scope:
Add the following to Initialize after initializing FlatRedBall:
Add the following to Update:
CursorWorldXAt.png

Additional Arguments

The WorldXAt and WorldYAt methods can also be passed Cameras and Layers if the default is not being used. Most commonly when working with HUD in Glue, you may add the HUD element to a 2D Layer, and this 2D Layer may have a settings that differ from your default Camera. In this case, you should use these available overrides. Specifically, if you are working in an Entity, you can use the following:

Using custom Cursor graphics

The WorldXAt and WorldYAt methods can be combined with Sprites and Layers to create a custom cursor. The following code shows how to create a custom cursor using the redball.bmp graphic. This code assumes a 2D coordinate system. You will need to adjust the Sprite size appropriately if using 3D coordinates instead:

Add the following at class scope:
Add the following to your game or Screen’s Initialize/CustomInitialize:
Add the following to your game or Screen’s Update/CustomActivity:

Method Limitations

The WorldXAt and WorldYAt methods may giave unexpected results if the Camera is rotated. These methods should only be used when the Camera is facing down the Z axis (default orientation). For a rotated Camera, the Cursor’s GetRay method should be used. If interested in object picking, you can use the Cursor’s IsOn3D method or the IClickable or IWindow interfaces for Entities in Glue.