The ResolutionOrOrientationChanged event is an event which is raised whenever the game's resolution or orientation changes. This can happen if:
The orientation changes (on a mobile or tablet)
The user docks your game in Windows 8
The user changes the window resolution - either through a command in the game or by resizing the window
This example assumes a desktop application. It will allow the user to resize a window by dragging the corner/edges. Whenever the user does this the new resolution will be printed to the screen. First, add the following code to your Screen's CustomInitialize:
To add the ResolutionOrOrientationChanged event:
Open or focus on Glue
Right-click on your Screen's Events item
Select "Add Event"
Verify "Expose an existing event" is selected
Use the drop-down to select "ResolutionOrOrientationChanged"
Click OK
Next, go back to Visual Studio and open your screen's Event file. If your screen is called "GameScreen" then the event file will be "GameScreen.Event.cs". Add the following code to OnResolutionOrOrientationChanged:
The FRB Editor supports the addition of events to screens and entities. The most common types of events include:
Responding to a variable changing. For more info see the Variable Event page.
Responding to collision (on a CollisionRelationship)
Other objects such as IWindows can also expose events, but these are less common.
The only type of event which requires using the FlatRedBall Editor is variable events. All other events can be performed purely in code. CollisionRelationship events are often defined in the FlatRedBall Editor since doing so provides a single place to see all responses to a collision.
Variable events allow for custom code to react to a variable being assigned. To add an event for a variable:
Create a variable on your entity
Drag+drop the variable onto the Events folder
This creates an event in the Event.cs file for the container. For example, if the event is created in the Player entity, then the event handler is added to Player.Event.cs.
Note that IWindows are not used as often in modern FlatRedBall development due to the introduction of FlatRedBall.Forms. However, the following example does show how events can be used for custom implementations of IWindow. The events available to a screen, entity, or object depend on the respective container's properties. For example, if an entity implements IWindow (for more information, see the Implements IWindow page), the entity will have additional events available.
Every event in Glue creates a corresponding method in your code project which can be edited in Visual Studio. For example, consider the example of a GameScreen which has an event ResolutionOrOrientationChanged:
The presence of this event will result in 2 new code files:
GameScreen.Event.cs
GameScreen.Generated.Event.cs
As usual, the file with Generated in the name is a generated file which should not be edited because Glue may overwrite any manual changes. The non-generated file (GameScreen.Event.cs) can be freely edited to modify the logic associated with a given event.