Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
AxisAlignedRectangles are rectangular shapes which cannot be rotated. AxisAlignedRectangles can be used as collision objects. For information on using AxisAlignedRectangles in code, see the AxisAlignedRectangle code page.
To add an AxisAlignedRectangle to an entity:
Expand your entity
Right-click on the Objects item
Select "Add Object"
Enter the name "Collision"
Set the SourceType to "FlatRedBallType
Objects in Screens and Entities can be of type Camera. A Camera object will (by default) represent the main Camera (FlatRedBall.Camera.Main). If an object in an Entity is a Camera, then this will (by default) attach the main Camera to the Entity. If an object in a Screen is a Camera, then this object serves as an alias for FlatRedBall.Camera.Main, but no attachment occurs.
Cameras added to a Screen can be modified in the FlatRedBall Editor. By default, adding a Camera object to a Screen does not create a new Camera, but rather it provides access to the main Camera. For more information, see the IsNewCamera property below. To access the camera in a Screen:
Select the Screen to contain the object. To make changes for all levels, select the GameScreen.
Click the Add Object button to add a new object to the screen
Select Camera as the type and click OK
The new camera appears in the GameScreen. It can be modified to make changes to the game, including in edit mode. For example, the Background Color can be changed from Black to any desired color.
The IsNewCamera property is a property which only appears on objects which are of type Camera.
If this property is false (the default value) then the Camera object is assigned to the main Camera (FlatRedBall.Camera.Main).
If this property is true, Glue will create a new Camera instance. This is not often used but can be used for split-screen games.
If you are developing a game which requires logic for initializing or controlling the Camera then you may want to organize this code into an Entity. The Camera object facilitates setting this up in Glue. The process is as follows:
Create an Entity which will contain all of the logic. For example an Entity named CameraEntity
Right-click on the CameraEntity's objects and add a new object
Select Camera as the type
Now you can code logic in the CustomInitialize and CustomActivity of your CameraEntity.
Set the SourceClassType to "AxisAlignedRectangle"
The CameraControllingEntity provides a standardized way to control camera position in games which contain a moving character or which use Tiled for maps.
If your game was created with the wizard, then your GameScreen has an instance called CameraControllingEntityInstance.
This instance targets the PlayerList (averages the position of all Players in the PlayerList) and will restrict the visible area to the Map object.
The Extra Map Padding property adds a number of pixels of offset between the edge of the actual map and the desired visible edge. A positive value adds padding, effective shrinking the available area that the camera can view. A negative value allows the camera to move outside of the map. Note that the property on the CameraControllingEntity is called Map since this is the most common type of object used to control bounds, but it doesn't have to be a map.
You can manually add a new instance to your game if you do not already have an instance in the GameScreen. Keep in mind this may have already been done for you if your game was created using the new project Wizard. To add a CameraControllingEntity to a game that has not used the Wizard:
Select your GameScreen
Select the Quick Actions tab
Click the Add Object to GameScreen button
Select the Camera Controlling Entity option
Click OK
Once you have created the instance, you can assign it the object to follow and the map to use as the visible bounds. To set which object the camera will follow:
Select the newly-created CameraControllingEntityInstance
Click the Variables tab
Select which object to follow in the Targets list. Notice that you can select entire lists of objects too, which will result in the CameraControllingEntity using the center position for all objects.
Similarly, the Map object can be set to control the visible bounds of the camera using the Map dropdown.
At runtime the Camera will automatically follow the target with no additional code required.
The Circle object is commonly used for collision and as a placeholder graphic in game development. Circles can be added to entities which implement the ICollidable interface to act as the entity's collision shape.
To add a circle to an existing entity:
Expand the entity
Right-click on the entity's Objects folder
Select Add Object
Verify the FlatRedBall or Custom Type option is selected
Select Circle
Click OK
Circles can also be added to a new entity. To do this:
Right-click on Entities
Select Add Entity
Check the Circle option. Notice that this automatically checks the ICollidable check box.
The DestinationRectangle can be used to make a Layer only draw to part of a Screen. This is often referred to as "masking" or "creating a mask". The DestinationRectangle property in Glue functions the same as in code. For a technical discussion on destination rectangles for Layers, see this page.
The DestinationRectangle can control the area of the screen where a Layer is drawn. By default the DestinationRectangle is blank in Glue, meaning that the Layer will occupy the same area on screen as the main Camera.
This destination rectangle can be changed in Glue. To do this:
Right-click on "DestinationRectnagle" in Glue.
An option for "Use Custom Rectangle" should appear
Select this option and the Layer will be given a custom rectangle:
Now that the DestinationRectangle value is there, we can modify it easily by changing one of the four values, or by expanding the DestinationRectangle and modifying each value independently:
Consider a Sprite which takes up nearly the entire screen:
If this Sprite were put on the Layer, it would look like this:
The Is2D option can be used to make a Layer use 2D coordinates. Layers which are 2D can be used even if the current Camera is in 3D. Layers which are 2D are often used to create HUDs and UI Screens.
For information on how to use Layers in code, see the Layer reference page.
The most common usage of the Is2D property is to create a 2D layer in a game which uses a 3D camera. Typically 3D games will have some type of 2D hud, so a 2D layer is needed to hold hud.
This example shows a simple setup where a 2D layer can be used on a 3D graphic. First, the game is set up to use a 3D camera.
Next, a Sprite is added to a GameScreen. It has the following variable values:
Texture = GroundTexture
Right Texture Pixel = 512
BottomTexturePixel = 512
Texture Address Mode = Wrap
Y = -10
Rotation X = 1.5708
The GameScreen has a layer named Layer2D for 2D objects.
Finally the GameScreen has a Text instance called GameOverText which has been placed on Layer2D.
The result is SpriteInstance is drawn in 3D, but the GameOverText is drawn and positioned in 2D.
The FRB Editor supports the creation and management of CollisionRelationship objects. This document covers the features provided by the FRB Editor, and explains common scenarios where you may need to interact with the CollisionsRelationships in code. Most cases can be handled by CollisionRelationships in the FRB Editor; however, more advanced situations can be handled in code. For information about creating and working with CollisionRelationships in code, see the CollisionManager page.
CollisionRelationships define how to respond when two types of objects collide (overlap). Examples of reactions to overlapping objects include:
A player must take damage when colliding with a bullet
A bullet must be destroyed when colliding with a wall
An enemy must be moved so that it doesn't overlap the same space as another enemy
A car must reduce its maximum speed when driving over grass
Even simple games will require multiple relationships, and larger games may include dozens of relationships. Glue makes the creation and management of these much simpler than management purely in code.
Collision relationships can be created between:
Lists of entities which implement ICollidable
Individual Entity instances which implement ICollidable
TileShapeCollections
ShapeCollections (regular, as opposed to TileShapeCollections)
All CollisionRelationships will at include at least one Entity or Entity list, so it is important to mark Entities which you intend to use in relationships as ICollidable. For information on ICollidable entities, see the ICollidable Entity page.
CollisionRelationships can be created a few ways. Typically collision relationships are added to a screen, such as a base GameScreen. In this example we will use a screen called GameScreen which already has a few objects:
PlayerList (a list of Player entities)
BulletList (a list of Bullet entities)
EnemyList (a list of Enemy entities)
SolidCollision (a TileShapeCollection)
Note that the TileShapeCollection may have its SetByDerived value set to true. This allows the creation of CollisionRelationships in a base Screen even though the TileShapeCollection is created in a derived Screen.
You can drag+drop one collidable object (such as a list) onto another collidable object (such as another list or a TileShapeCollection) so long as the two objects are in the same screen. This will create a CollisionRelationship between the two objects.
The Collision tab displays when a collidable object or list is selected
The image above displays the Collision tab for the BulletList. Notice that the BulletList can collide with any of the other collidable objects in the GameScreen including itself. Adding collision is easy - just click the Add button next to the object in the Collision tab to create a new relationship. For example, clicking on the Add button next to EnemyList creates a relationship between BulletList and EnemyList.
CollisionRelationships are regular Objects which can be created through the right-click menu. To create a CollisionRelationship through the right-click menu:
Right-click on a Screen's Objects
Select Add Object
Verify FlatRedBall or Custom Type is selected
Select the CollisionRelationship type
Click OK
In this case the newly-created CollisionRelationship will not yet reference any collidable objects in the screen, and the game will not compile until the objects in the relationship are set (as shown in the next section).
Once a CollisionRelationship is created, it can be edited by selecting it under the Screen's Objects folder and clicking the Collision tab.
A CollisionRelationship objects can be changed using the two drop-downs. Note that if the Auto-name Relationship checkbox is checked, the name of the relationship will automatically change when either of the two objects in the relationship changes. Of course, if you create CollisionRelationships using either the Add button or the drag-drop method, you do not need to set the object types.
Subcollision allows specifying a specific shape within a collidable entity to use when performing collision. This is useful if an entity includes multiple shapes, each for different purposes. For example, an enemy may have a circle for solid collision (preventing the enemy from walking through walls) but it may also have a line for line-of-sight collision. In this case, we do not want the line to collide against the walls, so we would specify that only the enemy's circle should collide with the walls. All available shapes for subcollisions appear in the Subcollision dropdowns for each object. Note that changing the subcollision will also rename the CollisionRelationship if the Auto-name Relationship option is checked.
Physics can be set up through the Collision tab which offers multiple options.
:
No Physics - Colliding objects will not automatically have their positions or velocities changed by the CollisionRelationship.
Move Collision - Colliding objects will be separated if a collision occurs using their relative mass values. The most common values for First Mass and Second Mass are 1, 1 if both objects have equal mass and 0, 1 if the first object should not be able to push the second (in the case of colliding against a solid TileShapeCollection)
First Mass - the mass of the first object in the relationship (the mass of enemies) relative to the mass of the second object. If this object should not be able to push the second object, it should have a mass of 0.
Second Mass - the mass of the second object relative to the first object. If this object should not be able to push the first object, it should have a mass of 0.
Move Soft Collision - Colliding objects will be separated, but gradually over time. This creates a "soft" feel, allowing objects to overlap and push each other around.
Bounce Collision - Colliding objects will be separated if a collision occurs. They will also have their velocity adjusted in response to the elasticity value. An elasticity value of 1 will preserve momentum. An elasticity of 0 will be an inelastic collision - where momentum is lost.
First Mass/Second Mass - see Move collision
Elasticity - A multiplier for an object's velocity when it collides. A value of 0 will absorb momentum. A value of 1 will preserve momentum. A value greater than 1 will add momentum.
Physics can also be applied using collision events if your game needs to customize the behavior when a collision occurs. For example, you may want the relaitive masses between entities to vary rather than always being fixed.
In some cases games will need to perform custom logic when a collision occurs. For example:
A Player entity takes damage when colliding with a bullet
The Bullet entity being destroyed when colliding with a wall
An Enemy entity's movement speed being slowed when colliding with mud TileShapeCollection
Certain objects should have different masses when performing collision.
Collision events can be created by dropping a CollisionRelationship on a Screen's Events folder.
For more information on FlatRedBall events, see the FlatRedBall Events page. Like all other events, collision events can be edited in code. In the example above, the GameScreen.Event.cs file now includes an function OnEnemyVsPlayerCollisionOccurred which is called whenever a collision occurs between an Enemy and Player instance. Make sure to add code to <YourGameScreen>.Event.cs and not the <YourScreen>.Genererated.Event.cs.
Notice that the CollisionRelationship used in this example is between a list of Enemies and a list of Players, but the event is raised for a single Enemy and a single Player. Since each enemy may collide with each player, the event method may get raised multiple times per frame. Every time the event is raised, the arguments tell you which two objects collided.
For example, in the code above, you could destroy either the enemy (which is called first) or the player (which is called second) in the event. To destroy the enemy, you can do the following code:
To identify which shapes an entity collided against in a TileShapeCollection, the LastCollisionAxisAlignedRectangles property can be used. For more information see the LastCollisionAxisAlignedRectangles page.
If all entity instances have the same mass, then you can set your collision relationship physics through the FlatRedBall Editor. If your game requires custom masses, then you can implement your own physics in the collision event.
For example, the following code would adjust the player's mass so that it is higher if the player is shooting. This makes the player harder to move when shooting.
CollisionRelationships created in Glue will be automatically managed and will automatically perform their every-frame logic. In some cases games need to manually perform collision logic. For example, a game may need to first reset variables on an entity before collision logic is performed for that frame. In that case, the CollisionRelationships created in Glue can be modified in the CustomInitialize method of the GameScreen. For example, to disable the EnemyListVsPlayerList CollisionRelationship, the following code can be used:
Layers are a type of object which can be used to control the order in which visible objects in FlatRedBall are drawn. Most objects sort by their Z value. In other words, objects which are further from the Camera will draw behind objects which are closer to the Camera. Layers allow control over draw order without changing the Z of objects.
Layers are often used to draw certain categories of objects. For example, you may have regular game objects (such as trees, the ground, the sky), a Layer specifically for HUD elements (score, health, ammo), and another Layer for popup screens (pause screen, disconnected controller screen). Layers can also be used to draw visuals in 2D coordinates on top of a 3D Camera.
To create a Layer in the FRB Editor:
Select a Screen or Entity which will contain the Layer. Usually Layers are added to Screens.
Click the Quick Actions tab
Click the Add Object button
Select Layer
Click OK
Layers are drawn in the same order that they are added in code. In other words, if Layer1 was added first, then Layer2, Layer1 would draw first, then Layer2 would be drawn on top of Layer1. Similarly, the order of Layers in Glue impacts the order that they are drawn. Layers draw top-to-bottom. Therefore, the first layer when looking at the list of elements in Glue will be drawn first, and any subsequent Layers will be drawn on top.
You can adjust the order of layers by right-clicking on a Layer and selecting one of the options to move it:
To add an object to a layer:
Make sure you have a Layer in the same Screen as your object
Drag+drop the object onto the layer
For a general tutorial on Layers in Glue, see the page. For information on using Layers in code, see the page.
You can verify that the layer was changed by looking at the LayerOn property. Entity instances can be moved to a layer in code using the function.
RenderTarget2D instances can be created in the FRB Editor. When created in the FRB editor, they have the following behavior:
They will automatically match the resolution of the screen
They will be cleaned up when the Screen is destroyed
For an example on using RenderTarget2Ds with FlatRedBall Layers, see the Layer RenderTarget page.
PositionedObjectLists in Glue represent lists of objects which can be positioned. Positioned objects include:
Any Entity
Circles
AxisAlignedRectangles
Texts
Sprites
In code all of the objects mentioned above inherit from the FlatRedBall.PositionedObject class. The list above is just some of the most common types.
By default Glue will attempt to create lists for new entities automatically if the default options are left. For example, the following animation shows that Glue will add a new list to GameScreen when an entity called EnemyEntity is created.
Glue provides a number of methods for creating a new PositionedObjectList in a GameScreen
If your game has a GameScreen, and if your GameScreen does not already contain a list for an entity, then the Quick Actions tab shows a button to add a list to the GameScreen. Clicking this button will automatically add the list to the GameScreen.
Entity lists can be created by right-click drag+dropping an entity into a screen:
PositionedObjectLists can also be created through the regular right-click menu in an screen or entity's Objects node:
Right-click on Objects
Select Add Object
Make sure FlatRedBall or Custom Type is selected
Select PositionedObjectList<T>
Select the type of list to create using the dropdown
Enter the name of the list
Once a list has been created, instances of the list's type can be added:
Right-click on the list
Select Add Object
Instances can also be added to a list by first creating them outside of the list and dragging them onto the list. This is how instances of a derived entity type can be added to a list of a base type:
Instances (of the same type or of derived type) can be added to a list by dragging the entity directly on the list:
Polygons can be added to screens and entities to create complex collision. Polygons will automatically be used in an entity's collisions if the entity is marked as ICollidable in Glue. For information on working with the Polygon object in code, see the Polygon class reference.
Polygons can be added to entities:
Select the entity which will have the Polygon
Select the Quick Actions tab
Click the Add Object button
Select the Polygon type
Click OK
If the containing Entity is an ICollidable, the Polygon will automatically be used when performing collision.
Polygons can be edited through the Points tab, which appears when selecting a Polygon.
The FlatRedBall Editor supports creating objects of type ShapeCollection. You can create a ShapeCollection by following these steps:
Right-click on Objects under a Screen or Entity
Select "Add Object"
Verify that "FlatRedBall or Custom Type" is selected.
Select "ShapeCollection"
Click OK
Note that FlatRedBall also supports the .shcx file format, but this is no longer recommended. The PolygonEditor tool is no longer maintained, and the recommended approach is to add a ShapeCollection as shown above and to modify the shapes using FlatRedBall's LiveEdit.
ShapeCollections can have shapes added manually. The ShapeCollection serves as a "list" of shapes, but unlike normal lists, the ShapeCollection can contain multiple types of objects.
To add a new shape to the ShapeCollection:
Right-click on the ShapeCollection instance
Select Add Object
Select one of the shapes - notice that FlatRedBall filters the available types to the types allowed in a ShapeCollection.
Click OK
Your newly-created shape is added to ShapeCollection in the tree view.
Glue will only ask for the new instance's name (the type will match the list type), so enter a name and click OK
For information on how to work with a ShapeCollection in code, see .
Sprites are used to render a texture to the screen. Sprites are one of the most common types of FlatRedBall objects. Examples of Sprites include:
Character graphics (static or animated)
Backgrounds
Particles
Bullets
Sprites are often contained in Entities or created in code as particles.
If you know that your entity needs a Sprite, you can check the Sprite option in the Add Entity Window.
Right-click on the Entities folder
Select Add Entity
Check the Sprite option
Click OK
Sprites can be added to FlatRedBall screens or entities, although most games don't include Sprites directly in screens. To add a Sprite to an entity:
Create or select an existing entity or screen
Right-click on the Objects node
Select Add Object
Select the FlatRedBall or Custom Type category
Select the Sprite type
Click OK
Sprites usually display textures, which are created from image files such as .png files. To add and display a texture on a Sprite:
Create a Sprite in a screen or entity as shown above
Find a .png which you would like to use
Drag+drop the .png file onto your screen or entity's Files folder in FlatRedBall
Select the Sprite in the same screen or entity with the newly-added file
Change its Texture property to the newly-added file
For more information about working with textures, see the Texture2D page.
FlatRedBall Text objects can be used to display information to the player such as current score or character dialog. Glue supports creating and editing Text objects in screens and entities.
To create a Text object in Glue:
Right-click on the Object item in a screen or entity
Select Add Object
Select the "FlatRedBall or Custom Type" option
Scroll down and select the "Text" type
Click OK
Select the Text object
Set its Display Text value to some value like "Hello"
Click the Preview checkbox in Glue
Since Text objects are usually used for game UI, the following properties are usually set in Glue:
LayerOn - Text objects are usually placed on a UI or HUD layer
AttachToCamera - Text objects are usually displayed in a fixed position on screen
To see the Text object:
A SoundEffectInstance is a sound effect which provides a number of properties which can be used to modify how the sound is played back - for example volume, pitch, and whether the sound is looping. If a SoundEffectInstance is playing, it cannot be played again until the sound ends, or until the SoundEffectInstance is explicitly stopped. This can give precise control over how many sounds are playing at one time.
To add a SoundEffectInstance to your project:
Make sure you have a Glue project with a Screen or Entity which will contain the SoundEffectInstance.
Add a new WAV file to your Screen or Entity. For more information, the .WAV file page.
At this point the SoundEffectInstance will be available in code, but you cannot change any variables on the SoundEffectInstance. To do this:
Right-click on Objects
Select "Add Object"
Select the "From File" option
Select the .wav file you added as a file
Click OK
Select the newly-created object
Change "SourceName" to "Entire File (SoundEffectInstance)"
Once the file has been added to Glue, you need to change the RuntimeType to SoundEffectInstance:
After setting up the object, you can modify the variables of the object in Glue. To do so, select the object and scroll to the "Unset Variables" category. These variables can also be set through code: