• 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

[Tạo 2D Platformer Game với Godot] Part 16: Collecting Coins

AnonyViet by AnonyViet
January 27, 2023
in Tips
0

In this part, I will show you how to collect coins like other platformer games with Godot.

Join the channel Telegram of the AnonyViet 👉 Link 👈

Art

Download

As usual, I will provide the art.

You can download it at this link: Rotating Coins

Setting

[Tạo 2D Platformer Game với Godot]  Part 16: Collecting Coins

You create a new folder named VatPham in Folder Assets and then copy the Fill Coins.png in the zip file downloaded above.

Or if you already have enough knowledge, you can use another image.

Coins

Add scene

[Tạo 2D Platformer Game với Godot]  Part 16: Collect 19 . Coins

You create a new scene and Area2D is the root node -> rename to DongXu then you add 2 nodes like the picture.

Here, I use Area2D because I want when the Player touches it, the coin will identify and disappear, not using other nodes to do anything confusing.

[Tạo 2D Platformer Game với Godot]  Part 16: Collect 20 . Coins

Then you add a new animation and drag the image in order 1- > 8 ( and remove the number 5 ).

[Tạo 2D Platformer Game với Godot]  Part 16: Collect 21 . Coins

Enable playing in animatedsprite so that it always runs the animation.

[Tạo 2D Platformer Game với Godot]  Part 16: Collecting 22 . Coins

Then add collisionshape2d to it.

[Tạo 2D Platformer Game với Godot]  Part 16: Collect 23 . Coins

Then save the scene and add a script to it.

[Tạo 2D Platformer Game với Godot]  Part 16: Collect 24 . Coins

Then adjust the scale like the picture because it is quite big.

Script

[Tạo 2D Platformer Game với Godot]  Part 16: Collect 25 . Coins [Tạo 2D Platformer Game với Godot]  Part 16: Collect 26 . Coins

You connect the signal is body_entered because I want to check if the player goes in, the coin disappears and the number of coins in the player increases.

extends Area2D



func _on_DongXu_body_entered(body):
    if body.name == "Player":
        body.dongxu += 1
        queue_free()
    pass # Replace with function body

Therefore, I will have a code like this in the script of the coin.

Player

Script

var dongxu = 0

And in the player’s script, I just need to add 1 more line that is var dongxu = 0.

func _process(delta):
    $GUI/DongXu.text = str("Dong xu:" + dongxu)

Then I added one more function, _process(), I use it to run non-physics problems, this function will process faster than physics process.

$GUI/DongXu.text = str(dongxu) is that I will assign the text of node DongXu = with the value of the variable dongxu.

Note: when assigning a certain value to the text of a certain node, you always have to leave it in str() or else you will get an error because if you call .text, only String will be accepted.

Scene

Next, I have to add one more so-called to display the number of coins outside the screen for the player to know.

[Tạo 2D Platformer Game với Godot]  Part 16: Collect 27 . Coins

Add yourself a CanvasLayer -> GUI

One Label node -> DongXu
[Tạo 2D Platformer Game với Godot]  Part 16: Collect 28 . Coins

At the node label there is a so called text table and you can type there

[Tạo 2D Platformer Game với Godot]  Part 16: Collect 29 . Coins [Tạo 2D Platformer Game với Godot]  Part 16: Collect 30 . Coins

Then I adjusted the angle to make it reasonable.

Map

[Tạo 2D Platformer Game với Godot]  Part 16: Collect 31 . Coins

Then I will go out of the map to Instance.

[Tạo 2D Platformer Game với Godot]  Part 16: Collect 32 . Coins

Here is my final result.

[Tạo 2D Platformer Game với Godot]  Part 16: Collect 33 . Coins [Tạo 2D Platformer Game với Godot]  Part 16: Collect 34 . Coins

And when you pick up the coin, it will show up above the Label.

Summary

That’s it, see you in the next post.

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

Tags: coinsCollectingGameGodotPartPlatformertạovới
Previous Post

Instructions to register for a trial Windows VPS without VISA

Next Post

Parents should use Google Family Link to manage their children

AnonyViet

AnonyViet

Related Posts

Instructions on how to format text on the Windows 11 notepad
Tips

Instructions on how to format text on the Windows 11 notepad

August 16, 2025
4 ways to fix bluetooth connectivity on Windows 11
Tips

4 ways to fix bluetooth connectivity on Windows 11

August 8, 2025
How to know the computer is tracked and processed by Keylogger
Tips

How to know the computer is tracked and processed by Keylogger

August 7, 2025
Opal: Create applications who do not need to write code
Tips

Opal: Create applications who do not need to write code

August 3, 2025
How to activate a new Start menu on Windows 11
Tips

How to activate a new Start menu on Windows 11

July 29, 2025
Intellgpt: AI tool for osint and data science
Tips

Intellgpt: AI tool for osint and data science

July 28, 2025
Next Post
Parents should use Google Family Link to manage their children

Parents should use Google Family Link to manage their children

0 0 votes
Article Rating
Subscribe
Login
Notify of
guest

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Recent News

Instructions on how to format text on the Windows 11 notepad

Instructions on how to format text on the Windows 11 notepad

August 16, 2025
Instructions for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 2025
How to add application to your favorite bar

How to add application to your favorite bar

August 14, 2025
Instructions on how to format text on the Windows 11 notepad

Instructions on how to format text on the Windows 11 notepad

August 16, 2025
Instructions for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 2025
Online driving exam preparation: Support theory and practice

Online driving exam preparation: Support theory and practice

August 15, 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

Instructions on how to format text on the Windows 11 notepad

Instructions on how to format text on the Windows 11 notepad

August 16, 2025
Instructions for receiving 80GB of free data from VinaPhone from August 15

Instructions for receiving 80GB of free data from VinaPhone from August 15

August 15, 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í mm88 8XBET mm88 trang chủ new88

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í mm88 8XBET mm88 trang chủ new88

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