In this section, I will show you how to add Background and adjust the camera to make it more reasonable and beautiful.
Join the channel Telegram of the AnonyViet 👉 Link 👈 |
Character error
Then in the previous part, I showed you how to rotate the character and some of you will have an error that when rotating the character, it will fall or jerk, here is how to fix it.
You are getting the error that is because the character it is like this, because it is out of position.
You will have to reset the center position.
Then it won’t happen again.
Background
Download
In part 2, when I provided the link to download the tileset, it already included the background, if you delete it, you can download it again at the following link: Swamp 2D Tileset
Setting
You download and put the background image in Folder 2 Background into the folder Assets of the game.
Type 1
You guys add yourself the ParallaxBackground node
Add a Sprite node that is a child of the Background node.
You select the Sprite button and then drag the background image file to the Texture.
You will be like this.
And you remember for yourself that the blue frame is the frame that the user can see.
I will drag the background to fit the green frame.
Then run the game you will see the background it has appeared and always moves with you.
Type 2
If you want the background not to move with you then do the following.
You create one more ParallaxLayer node and put the Sprite as a child of that node.
Then at the button ParallaxLayer -> Motion you will see the Mirroring section, then at x you adjust to 1000 for yourself.
After adjusting to 1000 you will see that there will be 1 more background appearing and I call this Infinity Background.
You design your level to where you set the Background it there.
Camera
I will also show you how to optimize the camera to look good, if you look at the picture above, it won’t look good at all.
First, you have to see for yourself the coordinates that you want the camera to only move to by zooming in where you want to go and viewing in the coordinate bar.
Here on the left I want the maximum camera angle to be at coordinate 0, below it is 550, above it is 0 notes.
After I have the coordinates, I will go to Player -> Camera2D -> Limit and fill in the coordinates.
I will be like this after editing, it looks very good.
Camera by map
There will be different maps and each map’s camera you will have to limit differently, so if you adjust in Player, when in another map, this part will fail.
Therefore, I have this way so that you can adjust the camera limit according to each map.
You go to the map you want then select Player right click -> click Editable Children (allows you to edit the Instance node as a child node)
Then you find Camera2D and adjust it again.
Adjust the game when zooming in and out
When zooming in and out of the game according to the default settings, the game will not keep as default but it will be small
For example, this is when I zoom out.
And this is when zoomed out according to other settings.
It depends on the game you want to make and how you want it to be.
To be like this, you go to Project Settings, find Display, select Window and adjust in Mode, Aspect it has many modes for you to explore.
Summary
So in this part, I showed you how to add a background and adjust the camera so that it is reasonable.