The following tutorials provide an introduction to working with Platformers in the FlatRedBall Editor.
This page covers all control values available in a platformer entity. It also provides ways to implement common functionality such as ice physics and under-water levels.
If you created your game using the wizard, then the Player entity already has a set of default values. If you manually created your Player entity, then it should also have a set of default control variables.
These values serve as a starting point for platformers - they can be tuned to provide a custom feel to platformer entities. The platformer control values can be viewed and edited by selecting the Player entity and clicking on the Entity Input Movement tab.
This is the maximum speed (maximum absolute horizontal velocity) that the character can move through input. Note that if using Immediate horizontal movement, then this is a hard value - not other forces can modify the character movement. For more information, see the next section. Increasing this value makes the character move more quickly, but doing so can make the game more difficult to control if the value is too large.
This value controls whether the character reaches maximum velocity immediately, or if it takes time for the character to speed up and slow down to the maximum velocity and back to standing still. Using Immediate increases the responsiveness of your game, and allows players to move very accurately. Examples of immediate-movement games include Mega Man and Castlevania.
The Speed Up/Down option results in the platformer entity accelerating to max speed and back down to a standstill over time, instead of immediately. This option creates more natural movement and requires more planning on the player's part (such as building up speed before a big jump). Examples of speed up/down movement include the Super Mario Bros. series and the Donkey Kong Country series.
The Speed Up Time value controls how many seconds are required for the platformer entity to reach max speed. This value is only available if using Speed Up/Down horizontal movement.
Increasing this value makes the character makes the platformer entity feel sluggish. Decreasing this value makes the platformer entity feel more responsive. A value of 0 is identical to using Immediate horizontal movement. A larger speed up time can also be used for different terrains and environments. For example, a larger value can make the ground feel more slippery (if the character is walking on ice). A larger value can also make the character seem heavier, or can be used to simulate under-water movement. A larger Speed Up Time can be used for air movement so that control is less precise when in the air.
The Slow Down Time value controls how many seconds it takes for the platformer entity to decelerate from full-speed to a standstill. A larger value can make the ground seem more slippery, especially when paired with a larger Speed Up Time. Usually Slow Down Time should not be larger than Speed Up Time. If the two values are similar, then this makes the ground feel slippery. The following table shows common combinations of Speed Up Time and Slow Down Time. The values High, Medium, and Low do not have fixed meaning, but a typical setup may include these values:
Low .15 seconds
Medium .4 seconds
High .8 seconds
Of course, you should modify values to achieve the desired movement for your specific game.
Standard Ground Movement
Low or Medium
Low
Ice Ground Movement
High
High
Underwater Ground Movement
High
Medium
Air Movement
Medium
Medium
Heavy Character Ground Movement
High
Low
This value controls the velocity of the platformer entity at the moment when jumping off the ground, or when initiating a double-jump. Larger values allow the character to jump higher. This value is typically larger than Max Speed, but the exact value often requires multiple iterations to get the right feel.
A platformer entity's jump height is also impacted by Gravity, so both Jump Speed and Gravity may need to be modified together. A low jump speed can be used for double-jumps, or for swimming when under water. A large jump speed can be used for characters who can jump higher. The Jump Speed value on Air movement can control whether the character can perform a double jump. By default, this value is 0 which means that the character cannot double-jump. Setting a value greater than 0 means a character can double jump. This topic will be covered in more detail in the following tutorial.
If Hold to Jump Higher is checked, then the player will be able to hold the jump button to cause the platformer character to jump higher. This allows players to perform shorter hops when desired, and longer jumps to clear large obstacles. The larger this value, the longer the player can hold the button to jump higher.
Variable-height jumping can be implemented a number of different ways. The platformer entity implements variable height jumping by turning off gravity while the player is holding the button down. This approach has the following characteristics:
Jumps feel responsive and immediate - the platformer entity does not delay jumping while the player is holding the button down. Instead, jump height is determined by not applying acceleration immediately.
Jump motion may not appear totally fluid, especially in high-gravity games.
The following image shows two jump arcs. The first is the movement of the character when the button is held, the second is without:
Although it may be difficult to see, the entity moves in a straight line on the first part of the first jump, rather than moving in an arc. This is the result of gravity being turned off while the button is held. If we color the first part red, the linear movement is a little easier to see:
The Max Jump Hold Time value sets the maximum amount of time that the player can hold the jump button to extend the platformer entity's jump. A large value gives the player the option to hold the button to jump higher. A small value results in the max and min jump heights not differing by much. A very large value may result in the player appearing to "float" while jumping, so keep this in mind when setting large values (such as over 1 second). A large Max Jump Hold Time may be used with a small Max Jump Speed to create swimming controls.
This value controls whether the platformer entity can press the down arrow + jump to fall down through cloud collision. If this value is false, then cloud collisions can only be jumped up through, but the player cannot fall down through them.
This is the distance to fall when pressing down + jump on a cloud platform before testing cloud collision again. When falling through cloud collision, collision against clouds is temporarily disabled until the user has fallen far enough. Once that has happened, cloud collision is re-enabled. This value should be roughly the thickness of cloud collision objects plus the height of the player collision. For example, if the tile height is 16 and the player's collision height is 32, then the Cloud Platform Thickness value should be set to 48. If a TileShapeCollection's UpdateShapesForCloudCollision method is called, then only half of the shape will be used for collision, so only half of the tile height needs to be considered when determining the Cloud Platform Thickness.
Gravity controls how fast a character accelerates downward when falling. This value is assigned to the PositionedObject.YAcceleration property. Increasing this value makes the entity fall more quickly, while a smaller value makes the entity fall slower, or seem to float.
Max Falling Speed sets a limit to the platformer entity's y velocity. A smaller max falling speed results in the entity falling more slowly, even if Gravity is large. A smaller max falling speed can be used to slow a player's fall down with special abilities such as the raccoon tail in Super Mario Bros 3.
A smaller Max Falling Speed and low Gravity can be used to implement water physics such as the water levels in Donkey Kong Country.
This tutorial explores how to add double jump to a platformer character. It covers how to add an extra jump (double jump), infinite jumping, or a limited number of jumps in the air.
Double jumping is a feature in many platforms which gives the player more control over player movement. Players can use double jumping to remain in the air for a longer period of time, to reach areas higher than possible with a single jump, and improve horizontal movement precision. Entities which support double jumping require two sets of values - the movement values before double jump and the movement values to apply after double jump. Platformer entities automatically receive a platformer values called Air which are the before double jump variables, so we need to create a new set of values. To do this:
Select your platformer entity (Player)
Expand the drop-down next to the Add Movement Type button
Select Default Air Control option
Change the name of the new values to AfterDoubleJump
Now that we have a set of values for after double jump, we need to tell our game to use these new values for double jump:
Select the platformer entity
Click the Variables tab
Change the After Double Jump value dropdown to the name of the new set of values we just created (AfterDoubleJump)
Finally we need to change the Jump Speed value on the Air movement values to be greater than zero. This is the velocity which will be applied when performing a double jump.
Now the platformer entity (Player) supports double jumping.
We can also support infinite double jumps by either setting the AfterDoubleJump Jump Speed value to greater than zero, or by setting the AfterDoubleJump variable to be Air. This results in the character being able to jump indefinitely which can be useful if implementing swimming or abilities like the flying racoon power-up in Super Mario Bros 3.
As shown above, the platformer entity can support a single double jump by making the AfterDoubleJump variables have a Jump Speed of 0. By increasing the Jump Speed to greater than 0, then the platformer entity can jump infinitely similar to flying or swimming. It is also possible to limit the number of jumps, but this requires custom code.
For this example we will use the two movement types from the previous sections: Air and AfterDoubleJump. To limit the number of jumps, make sure that AfterDoubleJump has a Jump Speed value of 0.
Next we will conditionally assign the Air value in code AirMovement
value in code according to the number of jumps the player has performed since touching the ground.
To do so, open your platformer entity's code file (Player.cs) and modify the code as shown in the following snippet:
Now our platformer entity can jump 5 times, as controlled by a variable in HandleJump.
This tutorial covers how to read input to move a platformer entity. We will also be creating a level to test out our platformer entity. To create a level and collision, we will be using a Tiled level. For more information on working with Tiled, see the Tiled documentation.
Note - if you created your Platformer project using the wizard, feel free to skip this tutorial. This tutorial is only needed if you are manually creating your game.
The previous tutorial created a GameScreen which contains two TileShapeCollections:
SolidCollision
CloudCollision
By default, each is associated with a standard tile from the tileset included in our Level1Map.tmx. However, these collisions do not have any effect on our player since we haven't told the player to collide with them.
To set up collision between our PlayerList and SolidCollision:
Expand GameScreen Objects
Drag+drop the PlayerList onto the SolidCollision to create a relationship
Since our Player is marked as a Platformer entity, the FlatRedBall editor assumes that the PlayerVsSolidCollision relationship should use platformer physics. You can verify that this is the case by selecting the PlayerVsSolidCollision object and clicking on the Collision tab.
Now the player will collide with the level.
By default, the platformer entity already supports a default set of controls. To see this, select the Player entity, then select the Entity Input Movement tab.
By default, the platformer will be controllable with a plugged-in Xbox Gamepad. If no Gamepad is detected, then the entity can be controlled with WASD and Space.
Note - the animation above shows a game that is using the CameraControllingEntity to position the camera in the center of the map. If you are not using the CameraControllingEntity, then you can manually position the camera in your GameScreen by changing the Camera.Main.X
and Camera.Main.Y
variables in CustomInitialize
. Also, note that the Player is inside of the map. You can modify the player's starting X and Y values either in code or by selecting the Player1 object in GameScreen and changing its X and Y values.
If you want to override which input is used to move the player, you can change the controls in code. For example, to change the character to jump with the Enter key and to move with the arrow keys:
Go to GameScreen.cs
Modify the CustomInitialize function to contain the following input assignment code:
The code above added keyboard controls so that the Player can be moved horizontally with the Left and Right arrow keys and jumps using the Enter button.
Now our platformer character reacts to input and collides with the environment. We can change the environment by opening Level1Map at any time and painting new tiles. The next tutorial takes a deeper look at the control values.
This tutorial provides a set of steps for creating an entity with platformer behavior.
The FlatRedBall Editor provides a quick setup for creating a platformer project. To create a platformer project:
Launch the FlatRedBall Editor
Create a new project
Wait for the project to finish loading
Wait for the Wizard window to appear
Select the Platformer project option
Wait for the wizard to finish processing
Run the game from either Visual Studio or the FlatRedBall Editor
If you are using the wizard as shown above, you can skip this tutorial and the next tutorial and move on to the Movement Values tutorial. If you are interested in how to build a platformer in the editor "from scratch", keep reading.
Although this tutorial is focused on creating a platformer entity, we will first add a GameScreen. Creating a GameScreen first makes it much easier to add an entity after. Most FlatRedBall projects have a GameScreen - it's a standard screen created by the wizard, so it's best to follow this naming convention in your own projects even if you aren't using the wizard.
Note that you may already have a GameScreen in your project. If so, you can skip this section. To add a GameScreen:
Select the Quick Actions
Click the Add Screen/Level button
Leave the default GameScreen name
Check both the Add SolidCollision ShapeCollection and Add CloudCollision ShapeCollection options
Click OK
We will return to the GameScreen in future tutorials, but having one created before we create entities will speed up the process.
The Player entity is our entity that will be controlled and have platformer physics. Regardless of the genre, most FlatRedBall games have a Player entity. It's a convention that your games should follow, just like having a GameScreen.
To create an entity with platformer behavior:
Select the Quick Actions tab in Glue
Click the Add Entity button
Enter Player as the name for the entity
Check the AxisAlignedRectangle checkbox - platformer entities perform collision against their environment
Verify that the ICollidable checkbox is checked - this enables collision which is necessary for platforming physics
Change the Input Movement Type to Platformer
Leave the Tiled options selected to automatically create a list for this new entity in GameScreen
Click OK
This will create a new platformer entity with a rich set of default functionality. We can verify that the entity is marked as a platformer by checking its Entity Input Movement tab to verify that it is marked as a platformer and that it has two movement types:
Ground
Air
Now that we have the Player entity set up with platfomer control values, we can add it to our GameScreen by drag+dropping the Player onto the GameScreen node. We should already have a PlayerList in our GameScreen so the newly-added object will be inside of that list after the drag+drop.
Note that we add a Player to the GameScreen before creating any Levels. We add the Player to the GameScreen so that we have a player in every Level (screens which inherit from GameScreen).
To create a CameraControllingEntity:
Select GameScreen
Select the Quick Actions tab
Click the Add Object to GameScreen button
Find and select Camera Controlling Entity
Click OK
We want to set up the newly created CameraControllingEntityInstance to track our player as it moves around in the map. To do this:
Select CameraControllingEntityInstance under GameScreen/Objects
Select the Variables tab on the right
Set the variable Targets to PlayerList
Set the variable Map to Map
The camera should now be able to track the player. For more information on automatic camera control, see the CameraControllingEntity documentation.
This tutorial series primarily focuses on creating a platformer entity. If you would like to control the camera manually, you can do so by modifying Camera.Main. More information about the Camera object can be found on the Camera documentation page.
Before we can run our game, we also need to add a Level. Typically, the GameScreen includes objects, files, and objects which are common to all screens (such as a Player), while each level includes objects and logic which are level-specific (such as the TMX).
To add a level:
Select the Quick Actions tab
Click the Add Screen/Level button
Leave all defaults and click OK
After clicking OK, another popup appears with options for the level tile map (TMX). Leave all defaults and click OK
Your project should now have a Screen named Level1. This is marked as the startup screen (it has the play icon and appears in the startup dropdown).
If we run our game now, we'll see the entity functional - at least, it seems to fall with gravity. In the next tutorial we'll add collision and controls using our entity.