• 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: Collecting items in Godot Engine

AnonyViet by AnonyViet
February 1, 2023
in Tips
0

If you can follow this part, it proves that you are a very hard worker :D. This is the last part in the series of basic game programming with godot already. About 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 an advanced one.

Join the channel Telegram of the AnonyViet 👉 Link 👈

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

Groups:

This is a very useful feature of Godot, it helps you to define a button through Group

Here Group is the group and you can give each node a different group and use it to identify the node.

You can define the button with the command is_in_groups() or if you want to get the parent Node with the child node, use get_parent_in_group()

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

first. Is added in the Node Panel next to Inspector

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

2. It is added by Script with the add_to_group() command and this add_to_group() part, you should leave it 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 it first runs the game it Will be added to the group immediately

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

Setting Item:

You can Download Coin Games assets to get resources

First we will create a new sense Area2D.

Here we will use area2d because it has a singal that recognizes 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 boides collided and collects the item.

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

Then save it

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

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

Then add the track

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

Choose a Frame

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

Then you also add the key to the track as usual

Next we will create a script for the area2d.

Here we need to check if the body goes in is the player, it will disappear, otherwise if the monster goes in the coin it will disappear again, suffering :V and the player’s coin number will + 1.

So we will connect the signal body_entered

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

And after the connection is complete, we will create an if statement to identify the bodies that are player with Groups. Then the player’s coin variable will + 1 and will 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: Collecting items in Godot Engine 22

Then at the function _ready Let’s run the animation.

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

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

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

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

To be add_to_group("Player")

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

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

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

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

Then you set a mask/layer for it

Masks:

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

Layers:

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

Then in the Player’s Mask, please also tick the Coin box

So success r you can use it to do anything, it all depends on your imagination.

Next I will create a Label to display the number of Coins

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 songs here.

The article achieved: 5/5 – (100 votes)

Tags: CollectingEngineGameGodotitemslậpLessontrình
Previous Post

Introducing Web Application Vulnerability Miner

Next Post

Download Deep Freeze 8.6 Full Key – Disk Freeze Software

AnonyViet

AnonyViet

Related Posts

How to change the default font on Windows 10
Tips

How to change the default font on Windows 10

April 13, 2026
5 tips for using a Browser to replace an App (helps save RAM, time and money)
Tips

5 tips for using a Browser to replace an App (helps save RAM, time and money)

April 13, 2026
How to make funny MeMe photos without Photoshop within 10 seconds
Tips

How to make funny MeMe photos without Photoshop within 10 seconds

April 11, 2026
How to quickly design your own Logo without Photoshop
Tips

How to quickly design your own Logo without Photoshop

April 10, 2026
How to convert Website into App on Windows
Tips

How to convert Website into App on Windows

April 9, 2026
Instructions for getting 3 months of Adobe Express Pro for free
Tips

Instructions for getting 3 months of Adobe Express Pro for free

April 9, 2026
Next Post
Download Deep Freeze 8.6 Full Key – Disk Freeze Software

Download Deep Freeze 8.6 Full Key - Disk Freeze Software

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 add Watermark to Google Docs to protect copyright

How to add Watermark to Google Docs to protect copyright

April 19, 2026
How to intercept traffic using Burp Suite to analyze HTTP/HTTPS

How to intercept traffic using Burp Suite to analyze HTTP/HTTPS

April 18, 2026
How to avoid Adblock detection on Youtube with 4 good tips

How to avoid Adblock detection on Youtube with 4 good tips

April 17, 2026
How to transfer ChatGPT data to Claude is extremely simple

How to transfer ChatGPT data to Claude is extremely simple

April 16, 2026
How to add Watermark to Google Docs to protect copyright

How to add Watermark to Google Docs to protect copyright

April 19, 2026
How to intercept traffic using Burp Suite to analyze HTTP/HTTPS

How to intercept traffic using Burp Suite to analyze HTTP/HTTPS

April 18, 2026
How to avoid Adblock detection on Youtube with 4 good tips

How to avoid Adblock detection on Youtube with 4 good tips

April 17, 2026
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 add Watermark to Google Docs to protect copyright

How to add Watermark to Google Docs to protect copyright

April 19, 2026
How to intercept traffic using Burp Suite to analyze HTTP/HTTPS

How to intercept traffic using Burp Suite to analyze HTTP/HTTPS

April 18, 2026
No Result
View All Result
  • Home
  • News
  • Software
  • Knowledge
  • MMO
  • Tips
  • Security
  • Network
  • Office

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