mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-04 14:11:02 +03:00
[Instancing with signals] Updated to 4.0 (#6268)
* [Instancing with signals] Updated to 4.0 Basically started with changing `instance()` to `instantiate()` Was a good chance to also upgrade the badly named `b` variables into proper intuitive names. It's a good tutorial, short and to the point, though kinda abstract so I don't think there is anything more to add (if I put an image above the final codeblock, on how to add a signal via UI, it would ruin the abstraction imo) * Made the signal location a bit more obvious * Updated signal emission to 4.0 syntax Interesting that emit_signal did work, backwards compatibility ftw! `emit_signal()` its less intuitive as you must know a "magical function" of Godot instead of using the obvious variable, and also takes string argument lmao
This commit is contained in:
committed by
GitHub
parent
70133f3712
commit
6c566613a8
@@ -63,7 +63,7 @@ You could do this by adding the bullet to the main scene directly:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
var bullet_instance = Bullet.instance()
|
||||
var bullet_instance = Bullet.instantiate()
|
||||
get_parent().add_child(bullet_instance)
|
||||
|
||||
.. code-tab:: csharp
|
||||
@@ -96,8 +96,8 @@ Here is the code for the player using signals to emit the bullet:
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT and event.pressed:
|
||||
emit_signal("shoot", Bullet, rotation, position)
|
||||
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
|
||||
shoot.emit(Bullet, rotation, position)
|
||||
|
||||
func _process(delta):
|
||||
look_at(get_global_mouse_position())
|
||||
@@ -129,17 +129,17 @@ Here is the code for the player using signals to emit the bullet:
|
||||
}
|
||||
|
||||
In the main scene, we then connect the player's signal (it will appear in the
|
||||
"Node" tab).
|
||||
"Node" tab of the Inspector)
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
func _on_Player_shoot(Bullet, direction, location):
|
||||
var b = Bullet.instance()
|
||||
add_child(b)
|
||||
b.rotation = direction
|
||||
b.position = location
|
||||
b.velocity = b.velocity.rotated(direction)
|
||||
var spawned_bullet = Bullet.instantiate()
|
||||
add_child(spawned_bullet)
|
||||
spawned_bullet.rotation = direction
|
||||
spawned_bullet.position = location
|
||||
spawned_bullet.velocity = spawned_bullet.velocity.rotated(direction)
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
|
||||
Reference in New Issue
Block a user