Continuing the series, today ad will continue part 7 which is moving between levels. Can be understood as moving back and forth to edit the senses. To learn about sence, please review from Lesson 0 of Game programming series with Godot. As for the level, do you guys play the game? mmorp then understand it is a level but in this it is a game screen. For example, if you play argry bird after stage 1, you will see that stage 2 is the Level I mentioned here. Without further ado, let’s get started.
Join the channel Telegram of the AnonyViet 👉 Link 👈 |
Create New Sense
The first step is to create a new sense for yourself with the button “+” next to the sence tab World
Okay like this:
Choose for yourself Other Node then press enter.Note select other node then press enter don’t press anything else. It will give you the black button
And we’ll need to save Node Player and Node Tilemap about as .tscn to be able to put it into another sence without redoing it. And the like Node other like enemy nice trap
By the following way:
You right click on Node Player And Node Tilemap Choose for yourself Save Branch As Sense
That means it will save the node you just selected as tscn and in this tscn you can put your node in any sence without doing another one.
You can leave it anywhere. But remember to create a folder containing files like this for compactness.
Here I will save it in the folder tscn
In the folder you will see there 2 tscn just saved as Tilemap and Player
And next is Import Tscn enter sense
Choose the one in the picture:
==>
And here you will see there are 2-4 node It depends on your tscn. Mine has 3:
- 1 is Player.
- 2 is TileMap.
- 3 Is Level 1 is World
You guys Instance 2 is Player and TileMap come in
And you’ll see it’s like old sense
Note: In tilemap you may not need to save it as tscn anymore, just create a tilemap node and then enter the tileset and design a new level, if you want this sence to be different
Well, you guys like to save this sence 2 for yourself as level 2 and save it in a certain folder, mine is in the sence folder and Click Ctrl + WILL to save
And below is my level 2. Next we will create an object that moves between levels
Creating Sense Move Object
To move between levels you will need to create a Move Sense Object. First, you create your own node area2D live sense 1 Please
Add me 2 in Area 2D
In the Sprite section, you put your photos in and you can find them online
And here is my picture:
After running the game
Next, you create yourself a new script in Area2D
Then the code is as follows
Here below:
Part export(String,FILE,"*.tscn") var next_world
this is the part it will take this out of the node’s settings and you can put tscn in there for it to point to
get_overlapping_boides
is a function that helps you check the bodies inside collection bodies enter collsion it will do something.
for body in boides
: for body in boides (just declared above) means that if a body is inside the boides it will execute the if statement below. this body is a command of this node, the body here is kinematicbody and staticbody
if body.name == player: body.name
ie body and then get its name if by Player it will execute the command below. Well, the “Player” is the name of your Player node. If your Node player has any name, you must replace it with “Player” to be effective.
get_tree.change_sence
this is an order of Godot help you move from sense this is sense other (next_world) is the function we declared above export.speak for easy understanding in Export it will allow you to give 1 sense Go in and then below if player touch the Object Move Sense then it will move Player arrive sense in the section Export
Next, you save it and return to the sence, you will see there Next World live Node Area2D Right side of the Place Script Variables.
Next, you click on the folder next to next world and choose the second sence
And it will be
Ah and we have to set collection for area2D Then the Player can move to another level
I have set it up and it can move to another level
And if you want better, you can do the following:
Set limit camera How much is it on the right, then adjust collsion of the sprite area2d behind the camera limit. When the camera reaches the number you set it will no longer move and after you move behind the limit camera player will be moved.