There are several ways of adding a background for a 2D game, such as:
- Adding one big image as a background
- Use several sprite objects that act as scenery together
- Use the tiled background object to create a repetitive background
- Use the tilemap object on a layer
But, even if that is a good method all the images are different sprites, this means that if you have a few hundred small sprites to create a floor and walls it could still slow the game. In this case you can use the tiled background object to create your level. The tiled background object is a special object for creating repetitive sprites, the advantage is that the tiled background object counts as one object (even if you've made about 100 repeated tiles for a floor). It makes the tiled background object very efficient for repetitive sprites.
The tilemap object is a new-ish feature of Construct 2 created to easily use a tilesheet image, a tilesheet is a collection of sprites in a single image. It also support an external level editor, Tiled which is commonly used as level editor in games. In this tutorial we'll use the tilemap object to create our background.
One thing to note is that the tilemap object fills an entire layer, so it's better to add more layers before working with it. To add a layer simply look at your layer bar and click on the "+" sign, it will add a layer on top of already created layers, remember that the free version of Construct 2 can only create 4 layers. Let's create 3 layers and rename them to: "HUD", "Main", and "Background. To rename a layer, click on a layer name and then click on the pencil icon.
Add a layer |
Three layers |
The top layer in the layer bar is the last to be drawn while the bottom layer is the first, meaning that the bottom layer can be overlapped by the above layer. Before we add the tilemap object let's move all current objects to the "Main" layer, because we don't want them to be overlapped by the background. To move an already created object to a different layer, first select the object we want to move and then look at the properties bar and you'll see a "Layer" property with dropdown list of available layers. Change it to "Main" and repeat it for every objects.
Changing the layer |
You won't see the tilemap anywhere, because it's still empty. To see the tilemap we need to draw some tiles onto it. So switch to the tilemap bar, which by default is located on the lower right with the objects bar (click on the tilemap tab on the bottom of it) and you'll see the tiles from the tilemap object.
Tilemaps |
Draw one tile at a time |
A few tiles at a time for the big rock |
Level example |
You may be wondering "How do I add a layer between two others?", well actually after you create a layer you can rearrange it by dragging it up or down. So after creating it, drag it to between the "Main" and "Background" layers. We don't want to accidentally change the background layer when we draw the other layer, so we'll lock it first. To lock a layer simply click the padlock icon to toggle lock/unlock, the locked layer can't be modified before it's unlocked again.
The fourth layer |
Adding rocks |
Now if you run the game you'll see that our character can't walk through the big stones. Congratulations! You just created your first game level, in the future we will create better looking scenes. If you don't want the rat to walk through the stones then you can add the solid behavior to them as well.
As always if you want to see the source code, you can get it from my Google Drive! Also, if you like what you read and what to support me writing this tutorials then consider pay my Patreon a visit. See you in my next tutorial.
Tidak ada komentar:
Posting Komentar