Quellcode durchsuchen

[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
TheYellowArchitect vor 2 Jahren
Ursprung
Commit
6c566613a8
1 geänderte Dateien mit 9 neuen und 9 gelöschten Zeilen
  1. 9 9
      tutorials/scripting/instancing_with_signals.rst

+ 9 - 9
tutorials/scripting/instancing_with_signals.rst

@@ -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