Creating an Entity
Introduction
This tutorial provides a set of steps for creating an entity with platformer behavior.
Using the Wizard
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.
Creating a GameScreen
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.
Creating a Player Entity
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
Adding a Player to the GameScreen
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).
Adding a CameraControllingEntity Instance (Optional)
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.
Adding a Level
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).
Conclusion
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.
Last updated