Custom Nodes in Godot 3.1: Class Name Keyword (tutorial)

  Рет қаралды 24,389

GDQuest

GDQuest

Күн бұрын

Пікірлер: 32
@AndrewWooldridge
@AndrewWooldridge 5 жыл бұрын
One question. You say "as always this project is available on github" but I don't see any links to github in the description or comments. Can you please add one for folks who may not know it already?
@AndrewWooldridge
@AndrewWooldridge 5 жыл бұрын
This is , in fact really super useful! I'm glad you created this tutorial. It was exactly what I was looking for.
@ClassyWolf
@ClassyWolf 3 жыл бұрын
Best tutorial for classes out there.
@ac11dc110
@ac11dc110 5 жыл бұрын
HOLLY WOW!?? I WAS JUST SEARCHING FOR THIS, 5MIN YOU UPLOAD
@annief151
@annief151 5 жыл бұрын
Hello GDquest. Thank you very much for taking the time to make these videos. If I may ask, could you possibly make a video on how to spawn things without the need of input from the user? May sound silly, but so far, all tutorials I've come across, the add_child call is always reliant on some sort of key press or mouse press. Thank you! Keep up the great work!
@pigdev
@pigdev 5 жыл бұрын
May I suggest some content? Maybe they can help. Using the Factory Method pattern to make spawners kzbin.info/www/bejne/pJO1c4iJjbqMp7c The spawners classes from my game github.com/pigdevstudio/moon-cheeser/tree/master/source/objects/spawners An older implementation, turn on the captions! kzbin.info/www/bejne/joSpdY2bnslphac
@willnationsdev
@willnationsdev 5 жыл бұрын
I believe answering your question requires more information. Scripting means plugging behavior into an existing system, so Godot has several callbacks it provides users to add logic. These are the "notification" methods which include the input functions, but also things like _init(), _enter_tree(), _exit_tree(), _ready(), _process(delta), etc. If you specify when it is you would like to spawn objects, we can provide an example of how that would work. In large part, you will always be doing something like this... var node = Node.new() # create & assign node.name = "Hello" # initialize properties add_child(node) # add to SceneTree ...or, for a scene... var scene = load("res://my_scene.tscn") add_child(scene.instance()) ...or, for a script... var script = load("res://my_script.gd") add_child(script.new())
@annief151
@annief151 5 жыл бұрын
I will check out the videos soon.
@annief151
@annief151 5 жыл бұрын
@@willnationsdev I am happy to give context, as I understand my question may have been a bit vague. My game I am currently using is a brick breaking type game. It contains 3 Nodes(Paddles, Walls, Bricks), and one node that was turned into a scene (Ball). So far the Paddle and the Ball are scripted. First the paddle. (I think you will see what I am trying to do, when you miss the ball with the paddle, and it falls off screen it is queued_free, I would like it to automatcally spawn with a vector) extends KinematicBody2D class_name Paddle var Ball = load("res://Mini Scene/Ball.tscn") func _ready(): set_physics_process(true) func _physics_process(delta): var y = position.y var mouse_x = get_viewport().get_mouse_position().x set_position(Vector2(mouse_x, y)) #func _Ball(): (This is one style I tried) # if Ball == queue_free(): # var Ball1 = Ball.instance() # add_child("Ball").set_position(position-Vector2(320, 352)) # print("Ball has been created") func _notification(Ball): if Ball != queue_free(): var new_ball = Ball.instance() new_ball.position = Vector2(0, 16) get_parent().add_child(Ball) And now here is the Ball script. extends RigidBody2D class_name Ball const SpeedUp = 10 const MaxSpeed = 300 func _ready(): set_physics_process(true) set_process_input(true) func _physics_process(delta): var bodies = get_colliding_bodies() for body in bodies: if body.is_in_group("Bricks"): body.queue_free() if body.get_name() == "Paddle": var speed = get_linear_velocity().length() var direction = position - body.get_node("Anchor").get_global_position() var velocity = direction.normalized()*min(speed+SpeedUp, MaxSpeed) set_linear_velocity(velocity) if position.y > get_viewport_rect().end.y: queue_free() print("Ball died")
@arturkarlov3000
@arturkarlov3000 5 жыл бұрын
what is ._shoot() (with the leading dot before the underscore)? I don't think I have seen this before.
@Gdquest
@Gdquest 5 жыл бұрын
The dot means "call this method on the parent class"
@arturkarlov3000
@arturkarlov3000 5 жыл бұрын
@@Gdquest Cool, thank you! is this a new thing or was it always there?
@IndividualFreedomNet
@IndividualFreedomNet 3 жыл бұрын
How do you inherit from an abstract base class like BaseButton and make it a concrete class? (I want to make my own button type which inherits BaseButton's features, but implement all the visual stuff myself as it's different from both the standard Button and TextureButton.)
@androidgameplays4every13
@androidgameplays4every13 5 жыл бұрын
I like your voice and pace.
@serge4264
@serge4264 5 жыл бұрын
Got a question That's fine buuut how to implement a non-inherited class? And furthermore include it to my script?
@SoftBreadSoft
@SoftBreadSoft 5 жыл бұрын
AI A script not attached to any node wont be inherited. Then to instance the class const name = load("res://thescript.gd") var theinstance = name.new() Then you can access the variables and methods in the class. E.g. theinstance.somemethod()
@Ach476
@Ach476 5 жыл бұрын
What is the benefit of referencing the class name to determine the node type vs using the node Group feature?
@igomesigomes
@igomesigomes 4 жыл бұрын
You can not rely on groups to be sure that every object it contains is of the same type.
@josesena4314
@josesena4314 5 жыл бұрын
Nice tutorial. Is there any actual advantage of using this other than type check?
@pigdev
@pigdev 5 жыл бұрын
this is type checking :D This feature allows you to make type checking easily. Before that you had to add something like const ClassName = preload("res://path/to/script.gd") and then check
@josesena4314
@josesena4314 5 жыл бұрын
@@pigdev I know. I just asked if there's any other advantage other than this. Thanks for answering anyway :D
@pigdev
@pigdev 5 жыл бұрын
@@josesena4314 Ohh, my bad. The major advantage is also getting autocompletion for your custom classes as well.
@pigdev
@pigdev 5 жыл бұрын
@@josesena4314 And of couse, casting etc...
@Kokounet
@Kokounet 5 жыл бұрын
Didn't your way of talking changed? it seems different from previous videos ! I really like your work by the way !
@tralavala9808
@tralavala9808 5 жыл бұрын
Atm there are 3 ppl that make tutorials here ;p
@Kokounet
@Kokounet 5 жыл бұрын
@@tralavala9808 oh okay I didn't know! Thanks
@Marvin-t3e
@Marvin-t3e 5 жыл бұрын
It can be confusion if you are using rudimentary assignments. Nice video anyway 😀
@yapayzeka
@yapayzeka 4 жыл бұрын
hard to understand. video is like a show off that presenter knows things.
Overview of the GLES2 Rendering Engine in Godot 3.1
7:51
GDQuest
Рет қаралды 11 М.
Godot Recipes: Animation States
10:31
KidsCanCode
Рет қаралды 107 М.
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
How to Make a Simple State Machine in Godot 3.1
8:10
Game Endeavor
Рет қаралды 94 М.
Using the Tileset Editor in Godot 3.1 (tutorial)
19:34
GDQuest
Рет қаралды 225 М.
Getting Started with Screen Sizes in Godot 3
7:08
GDQuest
Рет қаралды 92 М.
6 Tips to Better Organize your Godot Projects
11:39
GDQuest
Рет қаралды 136 М.