• Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
AnonyViet - English Version
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office
No Result
View All Result
AnonyViet - English Version
No Result
View All Result

[Lập Trình Game] Lesson 13: Collect items in Godot Engine

AnonyViet by AnonyViet
November 11, 2024
in Tips
0

If you can follow this part, it proves that you are a very hard-working person :D. This is the last part in the basic game programming series with godot Already. Regarding the Menu – Continue and Install, I will write it in the Tutorials article because it is outside the Series because this Series only guides you to program a basic game, not advanced.

Join the channel Telegram belong to AnonyViet 👉 Link 👈

In this part, I will guide you to collect coins. You can use it in many ways such as after collecting it, the game ends, if you don't collect enough within the time, you lose, etc.

Groups:

This is a very useful feature of Godot that helps you identify a button through a Group

Here Group is the group and you can put each button into a different group and use it to identify the button.

You can identify the node using the command is_in_groups() or if you want to get the parent node equal to the child node, use it get_parent_in_group()

And to add nodes to the group you can do 2 ways.

1. It is added in the Node Panel next to the Inspector

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

2. It is added by Script with the command add_to_group() and this add_to_group() part you should leave in the _ready function because the ready function is the function that will run the code when it first enters the game so we will put it there so that when we first run the game it will run. will be added to the group immediately

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Setting Item:

You can download assets Coin Games to get resources

First we will create a new sense Area2D.

Here we will use area2d because it has a singal that identifies bodies or areas that collide with it, so we will use it so that when the player touches it, it will send a signal that the boides have collided and collect the item.

Note: Here, our asset coin is SpriteSheet because there is only 1 row, so Vframe will = 0 Hframe, then you can count it yourself. If it is blurry, reimport it again.

Then save it

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Next we will create an Animation for it with AnimationPlayer. Create a Node and then create a new Aniamtion

Then add the track

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Choose Frame

[Lập Trình Game] Lesson 13: Collect items in Godot Engine

Then you also add a key to the track as usual

Next we will create a script for the area2d.

Here we need to check that if the body goes into the player, it will disappear, otherwise if the monster goes into the coin it will disappear, then woe :V and the player's coin count will be + 1.

So we will connect the signal body_entered

[Lập Trình Game]  Lesson 13: Collecting items in Godot Engine

And after the connection is complete, we will create an if statement to identify the bodies as players with Groups. Then the player's coin variable will + 1 and then self-destruct (queue_free()).

func _on_Coin_body_entered(body):
          if body.is_in_group("Player"):
                    body.coin += 1
                    queue_free()

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Then in the jaw _ready Let's run the animation.

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Next we will create a coin variable in Player so that when the player enters, the coin will + 1

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Then in the Player's func _ready() function, you add a command for it to go to Group

To be add_to_group("Player")

[Lập Trình Game]  Lesson 13: Collecting items in Godot Engine

Then you set the mask/layer to make sure it works :v

In Project Settings, I will add a new mask/layer called Coin

[Lập Trình Game]  Lesson 13: Collecting items in Godot Engine

Then you set a mask/layer for it

Mask:

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Layer:

[Lập Trình Game]  Lesson 13: Collect items in Godot Engine

Then in the Player's Mask, you also tick the Coin box

So if it's successful, you can use it to do anything, it all depends on your imagination.

Next, I will create a Label to display the Coin number

So that's the end of the basic game programming series with godot and later I will write 2D Tutorials and Visual Scripting with Godot.

You can Download Full Project Code Game Godot of 14 lessons here.

Previous Post

Experience YouTube Shopping easily in just 3 steps

Next Post

Basic operations on Scene2D – basic Godot Engine

AnonyViet

AnonyViet

Related Posts

How to write Shell Script in Linux/Unix
Tips

How to write Shell Script in Linux/Unix

December 6, 2025
How to completely uninstall WSL on Windows 11?
Tips

How to completely uninstall WSL on Windows 11?

December 6, 2025
Kinh nghiệm mua Laptop cho sinh viên nhóm ngành kế toán, kinh tế, xã hội…
Tips

Kinh nghiệm mua Laptop cho sinh viên nhóm ngành kế toán, kinh tế, xã hội…

December 5, 2025
8 tips for more successful PowerPoint presentations
Tips

8 tips for more successful PowerPoint presentations

December 4, 2025
Chrome extensions to improve productivity in 2021
Tips

Chrome extensions to improve productivity in 2021

December 2, 2025
How to create photos that run KPIs while crying using Gemini for the 12 zodiac animals
Tips

How to create photos that run KPIs while crying using Gemini for the 12 zodiac animals

December 1, 2025
Next Post
Basic operations on Scene2D – basic Godot Engine

Basic operations on Scene2D - basic Godot Engine

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

How to create Mind Map and Flowchart using ChatGPT is super simple

How to create Mind Map and Flowchart using ChatGPT is super simple

December 7, 2025
Free Gemini Google certification exam guide and Answers

Free Gemini Google certification exam guide and Answers

December 6, 2025
How to write Shell Script in Linux/Unix

How to write Shell Script in Linux/Unix

December 6, 2025
How to completely uninstall WSL on Windows 11?

How to completely uninstall WSL on Windows 11?

December 6, 2025
How to create Mind Map and Flowchart using ChatGPT is super simple

How to create Mind Map and Flowchart using ChatGPT is super simple

December 7, 2025
Free Gemini Google certification exam guide and Answers

Free Gemini Google certification exam guide and Answers

December 6, 2025
How to write Shell Script in Linux/Unix

How to write Shell Script in Linux/Unix

December 6, 2025
AnonyViet - English Version

AnonyViet

AnonyViet is a website share knowledge that you have never learned in school!

We are ready to welcome your comments, as well as your articles sent to AnonyViet.

Follow Us

Contact:

Email: anonyviet.com[@]gmail.com

Main Website: https://anonyviet.com

Recent News

How to create Mind Map and Flowchart using ChatGPT is super simple

How to create Mind Map and Flowchart using ChatGPT is super simple

December 7, 2025
Free Gemini Google certification exam guide and Answers

Free Gemini Google certification exam guide and Answers

December 6, 2025
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

trang chủ f168 nhà cái 78win https://www.qq8827.com/

No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

trang chủ f168 nhà cái 78win https://www.qq8827.com/

wpDiscuz
0
0
Would love your thoughts, please comment.x
()
x
| Reply