Camp Imagination Videogame Design Arena Shooter: Text
This lesson picks up where the Arena Shooter: Enemies lesson left off. Let's make our game look a little nicer. The black background of the default room is pretty boring.
- Right-click on Sprites in the resource tree.
- Choose "Create" to open the Sprite Editor.
- Name your sprite "sprBackground."
- Import the "tiles2" image from the "TutorialResources" folder.
We are going to use the image we imported as a tile set to fill the background. Our tiles are going to be 128x128 pixels. The upperleft corner of the image is empty since the first tile of a tile set is the blank tile, which is what you will see when you first add the tile set to the background.
- Right-click on Tile Sets in the resource tree.
- Choose "Create" to open the Tile Set Editor.
- Name your tile set "tileBackground."
- Click on "No Sprite" and choose the background sprite.
- Open the "Tile Properties" and change the "Tile Width" and "Tile Height" to 128.
We are now ready to add the tile set to our room.
- Open your room and click on "Create New Tile Layer" in the "Layers" section.
- Name the new layer "TileBackground."
- Drag the new layer between the "Instances" and "Background" layers.
- Change "No Tileset" to the background tile set.
You can now click on portions of the tile set on the right side of the screen and "paint" them onto your room. Let's make the room a bit bigger first before we do this.
- In the "Room Properties" in the bottom-left of the Room Editor, change the width to "2048."
- Use the tile set to paint tiles into the room.
- Click on the "Viewports and Cameras" arrow at the bottom of the "Room Properties."
- Click "Enable Viewports."
- Select "Viewport 0" and make it visible.
- In the "Object Following" section, select the player object.
- Set the horizontal and vertical borders to "256."
When your player moves around the screen, the viewport will follow. Once the player gets within 256 pixels of the edge of the viewport, the viewport will begin to move.
Let's keep score in the game by awarding 10 points every time an enemy is destroyed.
- Right-click on Objects in the resource tree.
- Choose "Create" to open the Object Editor.
- Name your sprite "objScore" and add the object to your room.
- Add a Create event to the new object.
- Add an Assign Variable action.
- Name the variable "score."
- Add a Draw event to the score object.
- Declare a temporary variable called "viewport" with a value "view_camera" using the Declare Temp action.
- Declare another temporary variable called "cameraX" with a value "camera_get_view_x(viewport).
- Declare another temporary variable called "cameraY" with a value "camera_get_view_y(viewport).
- Declare another temporary variable called "cameraWidth" with a value "camera_get_view_width(viewport).
- Add a Draw Instance Score action from the "Drawing" section.
- Change the "X" value to "cameraX + (cameraWidth / 2)" and the "Y" value to "cameraY + 25."
The score of 0 should now appear in the center of the screen and will move as the camera moves. We now need to make the score go up when an enemy is destroyed.
- Open the enemy object.
- Under the Destroy Instance action, add a Set Score action from the "Instance Variables" section.
- Assign a relative value of "10" to objScore.
The score should now go up by 10 everytime you destroy an enemy.
The default text for the score is a little small. To change it, we need to create a font.
- Right-click on Fonts in the resource tree.
- Choose "Create" to open the Font Editor.
- Name your font "fontScore."
- Select a font you like and increase the size to at least 24.
- Open the Draw event of the score object.
- Add a Set Font action and choose the "fontScore."
The score should now appear in the font you specified.