• 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

Windows 7/8.1/10 users will be upgraded to Windows 11 for free
Tips

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving ChatGPT Plus for 1 month for free in 2026
Tips

Instructions for receiving ChatGPT Plus for 1 month for free in 2026

July 28, 2026
Some reasons I don’t like Windows 11
Tips

Some reasons I don’t like Windows 11

July 27, 2026
Instructions on how to get free Facebook white ticks
Tips

Instructions on how to get free Facebook white ticks

July 27, 2026
Collection of Windows 11 wallpapers for computers and phones
Tips

Collection of Windows 11 wallpapers for computers and phones

July 26, 2026
Don’t install leaked Windows 11
Tips

Don’t install leaked Windows 11

July 25, 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

Recent News

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving the free Certified LLM Security Expert certificate

Instructions for receiving the free Certified LLM Security Expert certificate

July 30, 2026
MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

July 29, 2026
What is quantum resistant cryptography? Why must the Internet change?

What is quantum resistant cryptography? Why must the Internet change?

July 29, 2026
Windows 7/8.1/10 users will be upgraded to Windows 11 for free

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving the free Certified LLM Security Expert certificate

Instructions for receiving the free Certified LLM Security Expert certificate

July 30, 2026
MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

MSI laptops are not just for gamers: Which line is suitable for students, office workers and creative people?

July 29, 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

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

Windows 7/8.1/10 users will be upgraded to Windows 11 for free

July 30, 2026
Instructions for receiving the free Certified LLM Security Expert certificate

Instructions for receiving the free Certified LLM Security Expert certificate

July 30, 2026
  • Home
  • Home 2
  • Home 3
  • Home 4
  • Home 5
  • Home 6
  • Next Dest Page
  • Sample Page

say88 tỷ lệ kèo nhà cái kèo nhà cái 5 febet

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

say88 tỷ lệ kèo nhà cái kèo nhà cái 5 febet

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