• 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 20

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 post GIF photos on your personal facebook album – Share photo GIF
Tips

How to post GIF photos on your personal facebook album – Share photo GIF

September 18, 2025
How to target facebook ads prohibited content
Tips

How to target facebook ads prohibited content

September 17, 2025
How to back up Facebook images to Google Photos
Tips

How to back up Facebook images to Google Photos

September 16, 2025
How to receive 1 year Gemini Advanced free, Bypass verify sheerid
Tips

How to receive 1 year Gemini Advanced free, Bypass verify sheerid

September 16, 2025
Instructions on how to automatically delete temporary files on Windows 11
Tips

Instructions on how to automatically delete temporary files on Windows 11

September 16, 2025
Instructions for restoring old photos with Ai Gemini Nano Banana
Tips

Instructions for restoring old photos with Ai Gemini Nano Banana

September 15, 2025
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 display lunar calendar on iOS 26: See New Year, death anniversary without app

How to display lunar calendar on iOS 26: See New Year, death anniversary without app

September 19, 2025
How to see the new YouTube chart, replacing the top trending has been “killed”

How to see the new YouTube chart, replacing the top trending has been “killed”

September 19, 2025
How to post GIF photos on your personal facebook album – Share photo GIF

How to post GIF photos on your personal facebook album – Share photo GIF

September 18, 2025
Instructions for self -study English with Google ai Studio

Instructions for self -study English with Google ai Studio

September 18, 2025
How to display lunar calendar on iOS 26: See New Year, death anniversary without app

How to display lunar calendar on iOS 26: See New Year, death anniversary without app

September 19, 2025
How to see the new YouTube chart, replacing the top trending has been “killed”

How to see the new YouTube chart, replacing the top trending has been “killed”

September 19, 2025
How to post GIF photos on your personal facebook album – Share photo GIF

How to post GIF photos on your personal facebook album – Share photo GIF

September 18, 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 display lunar calendar on iOS 26: See New Year, death anniversary without app

How to display lunar calendar on iOS 26: See New Year, death anniversary without app

September 19, 2025
How to see the new YouTube chart, replacing the top trending has been “killed”

How to see the new YouTube chart, replacing the top trending has been “killed”

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

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí 8XBET https://kubet88.yoga/

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

©2024 AnonyVietFor Knowledge kqxs hôm nay xem phim miễn phí 8XBET https://kubet88.yoga/

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