# Creating a Screen

### Introduction

Screens and Entities are two common FlatRedBall concepts. A Screen represents a container for game content and other Entities. Screens define the flow of your game. Often game developers create many screens up-front to help think through a game's structure. Here are some examples of Screens in a typical game:

* Game play Screen (like the playing Screen in Pong). This is usually called "GameScreen"
* Splash Screen (like a FlatRedBall logo displaying splash Screen)
* Main menu Screen

### Creating a Screen

As you work with Screens you will find that they are very similar to Entities. To create a Screen:

1. Click on the **Screens** folder and select the **Add Screen** quick action...

   ![Add Screen/Level Quick Action](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-1efb631803b83b4f7a68b98d313f31909619a392%2F02_21_28_12.png?alt=media)

   ...or right-click on the **Screens** folder and select **Add Screen**

   ![Add Screen right-click option](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-dbae270863c2439710227c44cc168c44dd519b31%2F2022-01-img_61d314538a6f1.png?alt=media)
2. Uncheck **Add Map LayeredTileMap** option - Beefball doesn't use Tiled maps
3. Accept the other defaults by clicking **OK.**

   ![Add GameScreen dialog](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-4b1e52a8552c8ec2ebcd242dd5cc6dde78c28f19%2F2022-01-img_61d3149d379e1.png?alt=media)

Notice that FlatRedBall suggests the name **GameScreen** for your screen. Recommended practice is to always have the screen where your game takes place called GameScreen. If your game has multiple levels, each level would inherit from GameScreen. Since Beefball does not have multiple levels, we only create GameScreen.

### PlayerBallList in GameScreen

By default, your GameScreen now has a PlayerBallList - this is a list which will contain all PlayerBall instances in your GameScreen.

![PlayerBallList in GameScreen](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-dcef44f02338ccb48ebdb825527933afd57747db%2F2022-01-img_61d314ff1f447.png?alt=media)

If you unchecked the **Add Lists for Entities** option, or if you would like to know how to create lists manually, follow these steps:

1. Select the **PlayerBall** entity
2. Click the **Quick Actions** tab
3. Click the **Add PlayerBall List to GameScreen** button

![Add PlayerBall List to GameScreen quick action button](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-b35cfdab749e382a47da4e978eda72ecbb5b6a46%2F2022-01-img_61d315ce2af22.png?alt=media)

The PlayerBallList object will contain all of the PlayerBalls we plan on adding later. Our game is a two-player game, so it will eventually contain two PlayerBall instances. The PlayerBallList object will be used to define *collision relationships* in a later tutorial. Collision relationships define which objects can collide with each other (such as players vs the walls) and what to do when they collide (such as performing *bounce physics*).

### Adding an Entity Instance to GameScreen

Once you have at least one Screen in your game (GameScreen), you can add Entity instances to that Screen. Entities can be added through the editor or through game code. The editor provides a number of ways to add an entity:

* Drag+drop an entity on a screen to add an instance...

<figure><img src="https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-58ffc85fd2b2b7c1d665fcd9e06a58f838cbb03a%2F2016-01-03_08-28-03.gif?alt=media" alt=""><figcaption><p>Drag+drop PlayerBall into GameScreen PlayerBallList</p></figcaption></figure>

* ... or add an instance to the GameScreen by selecting **PlayerBall** and clicking the **Add PlayerBall Instance to GameScreen** quick action. Note that this option will only exist if you have a Screen called GameScreen...

  ![Add PlayerBall Instance to GameScreen quick action button](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-b73f1117364b1871337527b49c10e7df36f008d4%2F2022-01-img_61d3192850b6c.png?alt=media)
* ... or add an object to a screen by right-clicking on the GameScreen's **Objects** folder:
  * Right-click on your GameScreen's **Objects** folder
  * Select **Add Object**
  * Select **Entity** as the object type
  * Select **PlayerBall** as the type. The name will automatically be changed to **PlayerBallInstance**
  * Click **OK**

![Add new PlayerBall dialog](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-29f709b57e462ce700d541d4423f459f3d5fbd3a%2F2021-07-img_60fda9a9b4a8b.png?alt=media)

### Running your Game

Now that you have a PlayerBall instance in your GameScreen, you can run the game to see it. You can run the game through either the FlatRedBall Editor or Visual Studio.

* To run the game through the editor, click the Play button in the toobar at the top

  ![Running your game through the FlatRedBall Editor](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-3b1df1b86ef5b0b180fee2b33f6c29e90006ee2c%2F2022-01-img_61d319bb3bbb3.png?alt=media)
* To run the game through Visual Studio, click the Visual Studio icon to open the game in Visual Studio and run it like any other desktop project

  ![Visual Studio button in the FlatRedBall Editor](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-2722d912d71b8d96e30d8267c284ddcece15989f%2F2022-01-img_61d319d977080.png?alt=media)

Your game should now be open in Visual Studio.

![Start button in Visual Studio](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-5aebbd7aa28ace871a20f3fa4a236ca3bc31c2aa%2F2020-07-img_5f0a3e6ebc1a6.png?alt=media)

Once the game runs, you should see a circle (the PlayerBall1 instance) in your Screen.

<figure><img src="https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-723f204b71efc2383e7c8af3d93ff57571dd2fee%2F2020-07-img_5f0a421234957.png?alt=media" alt=""><figcaption><p>Game running with PlayerBall1</p></figcaption></figure>

### FlatRedBall Coordinates

Now that we have an object in our screen we can take a moment to understand how the coordinates in FlatRedBall work. By default, our entity exists at X=0 and Y=0. We can observe this by selecting the PlayerBall1 instance and looking at its Variables tab.

![PlayerBall1 position in the FlatRedBall Editor](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-7ebc69bd71a4c364745f72308564442658eff400%2F2023-09-img_650449103c08d.png?alt=media)

By default the center of the screen is at the origin (0,0), and objects are positioned by their center, so the PlayerBall appears at the center of the screen.

![PlayerBall1 positionied at (0,0) in  game](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-696c86b47cd30e589d5bdb4de7a7dc8a7fefffa1%2F2023-09-img_65044991b53a6.png?alt=media)

For more information on how to control the screen's resolution and world units, see the [FlatRedBall Resolution section](https://docs.flatredball.com/flatredball/glue-reference/camera).

For more information on how to control the Camera to change the center of the screen, see the [Camera code reference](https://docs.flatredball.com/flatredball/api/flatredball/camera).

### Conclusion

To recap we now have an Entity called PlayerBall which has a Circle. We've also created a GameScreen which contains an instance of our PlayerBall. If we run our game, it shows a white circle (our PlayerBall instance).

We're now ready to start adding some code to our project. The next tutorial covers controlling your Entity's movement.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flatredball.com/flatredball/tutorials/beefball/creating-a-screen.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
