Create Menu when the Level is out – LLODO


In this part, I will show you how to create a menu when you finish playing a level and it will be able to move to the next level, play again and return to the Level Map menu.

Copy Scene

So instead of having to recreate it from scratch, you can duplicate a new scene from the scene pause menu.

[Tạo 2D Platformer Game với Godot]  Part 25: Creating Menus when Levels run out

You find the pause menu in the filesystem right click and click duplicate

[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 52 is over

[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 53 is over

I will rename it EndLevelMenu
[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 54 is over

Then you delete the other nodes and leave them as shown, I changed the name NutTepTuc to LevelKeTiep

[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 55 is over

Edit text in TieuDe
[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 56 is over

You will clear the old script by pressing the button with the paper that has an x[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 57 is over [Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 58 is over

Then create a new one.[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 59 is over

Then 3 buttons, you disconnect because it is connecting to the old script.

[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 60 is over

Then reconnect 3 new ones.

[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 61 is over

Then Instance EndLevelMenu into Map.

Then you remember to hide the EndLevelMenu that belongs to the Control Node type.

Script

extends CanvasLayer



onready var level = get_parent().get_node("KhuVucDiChuyen")

func _on_NutLevelKeTiep_pressed():
    get_tree().paused = false
    get_tree().change_scene(level.LevelKeTiep)
    pass # Replace with function body.

func _on_NutChoiLai_pressed():
    get_tree().paused = false
    get_tree().reload_current_scene()
    print("choi lai")
    pass # Replace with function body.


func _on_NutVeMenu_pressed():
    get_tree().paused = false
    get_tree().change_scene("res://Scences/Map/LevelMap.tscn")
    pass # Replace with function body.

Here is the code of the EndLevelMenu script.

The 2 signals of the replay button and the menu will remain the same.

For LevelKeTiep to save time, instead of having to manually set it up to see what level it moves to the next level, I’ll take it. At the KhuVucDi Chuyen node, I have created a variable called LevelKeTiep and it carries the data of the next scene, so I will call that variable instead of doing it manually.

[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 62 is over

onready var level = get_parent().get_node("KhuVucDiChuyen"): is that I declare it and assign it with the parent node of the EndLevelMenu (as shown in the picture) and from that parent node I can access the KhuVucDi Chuyen node to get the data of the LevelKeTiep variable.

extends Area2D


export (String,FILE) var LevelKeTiep
onready var endlevelmenu = get_parent().get_node("EndLevelMenu")

func _on_KhuVucDiChuyen_body_entered(body):
    if body.name == "Player":
#		get_tree().change_scene(LevelKeTiep)
        endlevelmenu.get_node("EndLevelMenu").show()
        get_tree().paused = true

In the script of KhuVucDIChuyen, I changed it a little bit.

Here, instead of moving to the next level as usual, I will show it the EndLevelMenu and then stop the tree like in the pausemenu.

If you wonder why I got_node() 2 EndLevelMenu, please look at the image below.[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 63 is over

I call 2 EndLevelMenu because I have 2 nodes :).

[Tạo 2D Platformer Game với Godot]  Part 25: Create a Menu when Level 64 is over

And here are my results

Summary

In the next part, I will show you how to calculate the score after collecting the coins and when you go out of the LevelMap you will get the number of stars corresponding to the number of points.



Link Hoc va de thi 2021

Chuyển đến thanh công cụ