Преглед изворни кода

General changes to some pages in the "Step by step" section.

Michael Alexsander Silva Dias пре 7 година
родитељ
комит
922ceab77a

BIN
getting_started/step_by_step/files/autoload.zip


+ 4 - 4
getting_started/step_by_step/scene_tree.rst

@@ -77,13 +77,13 @@ two different ways:
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-        get_tree().get_root() # access via scenemainloop
-        get_node("/root") # access via absolute path
+        get_tree().get_root() # Access via scene main loop.
+        get_node("/root") # Access via absolute path.
 
  .. code-tab:: csharp
 
-        GetTree().GetRoot(); // access via scenemainloop
-        GetNode("/root"); // access via absolute path
+        GetTree().GetRoot(); // Access via scene main loop.
+        GetNode("/root"); // Access via absolute path.
 
 This node contains the main viewport, anything that is a child of a
 :ref:`Viewport <class_Viewport>`

+ 10 - 7
getting_started/step_by_step/scripting.rst

@@ -250,7 +250,7 @@ Next, write a function which will be called when the button is pressed:
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-    func _on_button_pressed():  
+    func _on_Button_pressed():  
         get_node("Label").text = "HELLO!"
 
  .. code-tab:: csharp
@@ -268,7 +268,7 @@ using :ref:`Object.connect() <class_Object_connect>`.
  .. code-tab:: gdscript GDScript
 
     func _ready():
-        get_node("Button").connect("pressed", self, "_on_button_pressed")
+        get_node("Button").connect("pressed", self, "_on_Button_pressed")
 
  .. code-tab:: csharp
 
@@ -285,7 +285,10 @@ The final script should look like this:
     extends Panel
 
     func _ready():
-        get_node("Button").connect("pressed", self, "_on_button_pressed")
+        get_node("Button").connect("pressed", self, "_on_Button_pressed")
+
+    func _on_Button_pressed():
+        get_node("Label").text = "HELLO!"
 
     func _on_button_pressed():
         get_node("Label").text = "HELLO!"
@@ -327,14 +330,14 @@ Why, hello there! Congratulations on scripting your first scene.
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-    # not for this case
-    # but just in case
+    # Not for this case,
+    # but just in case.
     get_node("Label/Button") 
 
  .. code-tab:: csharp
 
-    // not for this case
-    // but just in case
+    // Not for this case,
+    // but just in case.
     GetNode("Label/Button")
 
 Also, remember that nodes are referenced by name, not by type.

+ 18 - 18
getting_started/step_by_step/scripting_continued.rst

@@ -24,14 +24,14 @@ how many frames per second (FPS) the application is running at:
  .. code-tab:: gdscript GDScript
 
     func _process(delta):
-        # do something...
+        # Do something...
         pass
 
  .. code-tab:: csharp
     
     public override void _Process(float delta)
     {
-        // do something...
+        // Do something...
     }
 
 The delta parameter contains the time elapsed in seconds, as a
@@ -64,7 +64,7 @@ with the following script:
 
     func _process(delta):
         accum += delta
-        text = str(accum) # text is a built-in label property
+        text = str(accum) # 'text' is a built-in label property.
 
  .. code-tab:: csharp
     
@@ -75,7 +75,7 @@ with the following script:
         public override void _Process(float delta)
         {
             _accum += delta;
-            Text = _accum.ToString();
+            Text = _accum.ToString(); // 'Text' is a built-in label property.
         }
     }
 
@@ -114,12 +114,12 @@ all enemies can be notified about its alarm sounding by using
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-    func _on_discovered(): # this is a purely illustrative function
+    func _on_discovered(): # This is a purely illustrative function.
         get_tree().call_group("enemies", "player_was_discovered")
 
  .. code-tab:: csharp
     
-    public void _OnDiscovered() // this is a fictional function
+    public void _OnDiscovered() // This is a purely illustrative function.
     {
         GetTree().CallGroup("enemies", "player_was_discovered");
     }
@@ -279,8 +279,8 @@ other class-based datatype. For example:
 
     var s
     func _ready():
-        s = Sprite.new() # create a new sprite!
-        add_child(s) # add it as a child of this node
+        s = Sprite.new() # Create a new sprite!
+        add_child(s) # Add it as a child of this node.
 
  .. code-tab:: csharp
 
@@ -290,8 +290,8 @@ other class-based datatype. For example:
     {
         base._Ready();
     
-        _sprite = new Sprite(); // create a new sprite!
-        AddChild(_sprite); // add it as a child of this node
+        _sprite = new Sprite(); // Create a new sprite!
+        AddChild(_sprite); // Add it as a child of this node.
     }
 
 To delete a node, be it inside or outside the scene, ``free()`` must be
@@ -301,13 +301,13 @@ used:
  .. code-tab:: gdscript GDScript
 
     func _someaction():
-        s.free() # immediately removes the node from the scene and frees it
+        s.free() # Immediately removes the node from the scene and frees it.
 
  .. code-tab:: csharp
 
     public void _SomeAction()
     {
-        _sprite.Free();
+        _sprite.Free(); // Immediately removes the node from the scene and frees it.
     }
 
 When a node is freed, it also frees all its children nodes. Because of
@@ -327,13 +327,13 @@ This erases the node safely during idle.
  .. code-tab:: gdscript GDScript
 
     func _someaction():
-        s.queue_free() # immediately removes the node from the scene and frees it
+        s.queue_free() # Immediately removes the node from the scene and frees it.
 
  .. code-tab:: csharp
 
     public void _SomeAction()
     {
-        _sprite.QueueFree(); // immediately removes the node from the scene and frees it
+        _sprite.QueueFree(); // Immediately removes the node from the scene and frees it.
     }
 
 Instancing scenes
@@ -345,19 +345,19 @@ first one is to load the scene from your hard drive:
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-    var scene = load("res://myscene.tscn") # will load when the script is instanced
+    var scene = load("res://myscene.tscn") # Will load when the script is instanced.
 
  .. code-tab:: csharp
     
-    var scene = (PackedScene)ResourceLoader.Load("res://myscene.tscn"); // will load when the script is instanced
+    var scene = (PackedScene)ResourceLoader.Load("res://myscene.tscn"); // Will load when the script is instanced.
 
 
 Preloading it can be more convenient, as it happens at parse
-time:
+time (GDScript only):
 
 ::
 
-    var scene = preload("res://myscene.tscn") # will load when parsing the script
+    var scene = preload("res://myscene.tscn") # Will load when parsing the script.
 
 But ``scene`` is not yet a node. It's packed in a
 special resource called :ref:`PackedScene <class_PackedScene>`.

+ 17 - 19
getting_started/step_by_step/singletons_autoload.rst

@@ -55,7 +55,7 @@ This means that any node can access a singleton named "playervariables" with:
  .. code-tab:: csharp
  
     var playerVariables = (PlayerVariables)GetNode("/root/PlayerVariables");
-    playerVariables.Health -= 10; // instance field
+    playerVariables.Health -= 10; // Instance field.
 
 Or even simpler using the name directly:
 
@@ -66,7 +66,7 @@ Or even simpler using the name directly:
 
  .. code-tab:: csharp
 
-    // Static members can be accessed by using the class name
+    // Static members can be accessed by using the class name.
     PlayerVariables.Health -= 10;
 
 Custom scene switcher
@@ -125,7 +125,7 @@ loaded!
 
     func _ready():
             var root = get_tree().get_root()
-            current_scene = root.get_child( root.get_child_count() -1 )
+            current_scene = root.get_child(root.get_child_count() -1)
 
  .. code-tab:: csharp
 
@@ -150,7 +150,6 @@ current scene and replaces it with the requested one.
  .. code-tab:: gdscript GDScript
 
     func goto_scene(path):
-
         # This function will usually be called from a signal callback,
         # or some other function from the running scene.
         # Deleting the current scene at this point might be
@@ -160,26 +159,25 @@ current scene and replaces it with the requested one.
         # The way around this is deferring the load to a later time, when
         # it is ensured that no code from the current scene is running:
 
-        call_deferred("_deferred_goto_scene",path)
+        call_deferred("_deferred_goto_scene", path)
 
 
     func _deferred_goto_scene(path):
-
         # Immediately free the current scene,
         # there is no risk here.    
         current_scene.free()
 
-        # Load new scene
+        # Load new scene.
         var s = ResourceLoader.load(path)
 
-        # Instance the new scene
+        # Instance the new scene.
         current_scene = s.instance()
 
-        # Add it to the active scene, as child of root
+        # Add it to the active scene, as child of root.
         get_tree().get_root().add_child(current_scene)
 
-        # optional, to make it compatible with the SceneTree.change_scene() API
-        get_tree().set_current_scene( current_scene )
+        # Optional, to make it compatible with the SceneTree.change_scene() API.
+        get_tree().set_current_scene(current_scene)
 
  .. code-tab:: csharp
 
@@ -202,16 +200,16 @@ current scene and replaces it with the requested one.
         // Immediately free the current scene, there is no risk here.
         CurrentScene.Free();
 
-        // Load a new scene
+        // Load a new scene.
         var nextScene = (PackedScene)GD.Load(path);
 
-        // Instance the new scene
+        // Instance the new scene.
         CurrentScene = nextScene.Instance();
 
-        // Add it to the active scene, as child of root
+        // Add it to the active scene, as child of root.
         GetTree().GetRoot().AddChild(CurrentScene);
 
-        // optional, to make it compatible with the SceneTree.change_scene() API
+        // Optional, to make it compatible with the SceneTree.change_scene() API.
         GetTree().SetCurrentScene(CurrentScene);
     }
 
@@ -229,14 +227,14 @@ and scene_b.gd:
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-    #add to scene_a.gd
+    # Add to 'scene_a.gd'.
 
     func _on_goto_scene_pressed():
             get_node("/root/global").goto_scene("res://scene_b.tscn")
 
  .. code-tab:: csharp
 
-    // add to SceneA.cs
+    // Add to 'SceneA.cs'.
 
     public void OnGotoScenePressed()
     {
@@ -249,14 +247,14 @@ and
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-    #add to scene_b.gd
+    # Add to 'scene_b.gd'.
 
     func _on_goto_scene_pressed():
             get_node("/root/global").goto_scene("res://scene_a.tscn")
 
  .. code-tab:: csharp
 
-    // add to SceneB.cs
+    // Add to 'SceneB.cs'.
 
     public void OnGotoScenePressed()
     {

+ 4 - 3
getting_started/step_by_step/ui_code_a_life_bar.rst

@@ -95,7 +95,7 @@ scene:
 
         public override void _Ready()
         {
-            // C# doesn't have an onready feature, this works just the same
+            // C# doesn't have an onready feature, this works just the same.
             _bar = (TextureProgress) GetNode("Bars/LifeBar/TextureProgress");
             _tween = (Tween) GetNode("Tween");
             _numberLabel = (Label) GetNode("Bars/LifeBar/Count/Background/Number");
@@ -156,7 +156,7 @@ open its script. In the ``_ready`` function, we're going to store the
 
     public override void _Ready()
     {
-        // add this below _bar, _tween, and _numberLabel
+        // Add this below _bar, _tween, and _numberLabel.
         var player = (Player) GetNode("../Characters/Player");
         _bar.MaxValue = player.MaxHealth;
     }
@@ -316,6 +316,7 @@ It takes a new\_value as its only argument:
  .. code-tab:: gdscript GDScript
 
     func update_health(new_value):
+        pass
 
  .. code-tab:: csharp
 
@@ -408,7 +409,7 @@ clear its content. Let's animate the ``animated_health`` value. Call the
 
  .. code-tab:: csharp
 
-    // add this to the top of your class
+    // Add this to the top of your class.
     private int _animatedHealth = 0;
 
     public void UpdateHealth(int health)

+ 44 - 39
getting_started/step_by_step/your_first_game.rst

@@ -155,21 +155,21 @@ Start by declaring the member variables this object will need:
 
     extends Area2D
 
-    export (int) var SPEED  # how fast the player will move (pixels/sec)
-    var screensize  # size of the game window
+    export (int) var speed  # How fast the player will move (pixels/sec).
+    var screensize  # Size of the game window.
  
  .. code-tab:: csharp
 
     public class Player : Area2D
     {
         [Export] 
-        public int Speed = 0;
+        public int Speed = 0; // How fast the player will move (pixels/sec).
         
-        private Vector2 _screenSize;
+        private Vector2 _screenSize; // Size of the game window.
     }
 
 
-Using the ``export`` keyword on the first variable ``SPEED`` allows us to
+Using the ``export`` keyword on the first variable ``speed`` allows us to
 set its value in the Inspector. This can be handy for values that you
 want to be able to adjust just like a node's built-in properties. Click on
 the ``Player`` node and set the speed property to ``400``.
@@ -218,7 +218,7 @@ or ``false`` if it isn't.
  .. code-tab:: gdscript GDScript
 
     func _process(delta):
-        var velocity = Vector2() # the player's movement vector
+        var velocity = Vector2() # The player's movement vector.
         if Input.is_action_pressed("ui_right"):
             velocity.x += 1
         if Input.is_action_pressed("ui_left"):
@@ -228,7 +228,7 @@ or ``false`` if it isn't.
         if Input.is_action_pressed("ui_up"):
             velocity.y -= 1
         if velocity.length() > 0:
-            velocity = velocity.normalized() * SPEED
+            velocity = velocity.normalized() * speed
             $AnimatedSprite.play()
         else:
             $AnimatedSprite.stop()
@@ -237,7 +237,7 @@ or ``false`` if it isn't.
 
     public override void _Process(float delta)
     {
-        var velocity = new Vector2();
+        var velocity = new Vector2(); // The player's movement vector.
         if (Input.IsActionPressed("ui_right")) {
             velocity.x += 1;
         }
@@ -404,8 +404,8 @@ Add this code to the function:
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-    func _on_Player_body_entered( body ):
-        hide() # Player disappears after being hit
+    func _on_Player_body_entered(body):
+        hide() # Player disappears after being hit.
         emit_signal("hit")
         $CollisionShape2D.disabled = true
 
@@ -413,10 +413,10 @@ Add this code to the function:
 
     public void OnPlayerBodyEntered(Godot.Object body)
     {
-        Hide();
+        Hide(); // Player disappears after being hit.
         EmitSignal("Hit");
         
-        // for the sake of this example, but it's better to create a class var
+        // For the sake of this example, but it's better to create a class var
         // then assign the variable inside _Ready()
         var collisionShape2D = (CollisionShape2D) GetNode("CollisionShape2D");
         collisionShape2D.Disabled = true;
@@ -509,8 +509,8 @@ Add a script to the ``Mob`` and add the following member variables:
 
     extends RigidBody2D
 
-    export (int) var MIN_SPEED # minimum speed range
-    export (int) var MAX_SPEED # maximum speed range
+    export (int) var min_speed # Minimum speed range.
+    export (int) var max_speed # Maximum speed range.
     var mob_types = ["walk", "swim", "fly"]
 
  .. code-tab:: csharp
@@ -518,15 +518,15 @@ Add a script to the ``Mob`` and add the following member variables:
     public class Mob : RigidBody2D
     {
         [Export] 
-        public int MinSpeed = 150;
+        public int MinSpeed = 150; // Minimum speed range.
 
         [Export] 
-        public int MaxSpeed = 250;
+        public int MaxSpeed = 250; // Maximum speed range.
 
         private String[] _mobTypes = {"walk", "swim", "fly"};
     }
 
-We'll pick a random value between ``MIN_SPEED`` and ``MAX_SPEED`` for
+We'll pick a random value between ``min_speed`` and ``max_speed`` for
 how fast each mob will move (it would be boring if they were all moving
 at the same speed). Set them to ``150`` and ``250`` in the Inspector. We
 also have an array containing the names of the three animations, which
@@ -547,7 +547,7 @@ choose one of the three animation types:
     {
         var animatedSprite = (AnimatedSprite) GetNode("AnimatedSprite");
     
-        // C# doesn't implement gdscript's random methods, so we use Random
+        // C# doesn't implement GDScript's random methods, so we use 'Random'
         // as an alternative.
         //
         // Note: Never define random multiple times in real projects. Create a
@@ -666,15 +666,15 @@ instance.
 
         public int Score = 0;
 
-        // note: we're going to use this many times, so instantiating it
-        // allows our numbers to consistently be random
+        // Note: We're going to use this many times, so instantiating it
+        // allows our numbers to consistently be random.
         private Random rand = new Random();
 
         public override void _Ready()
         {
         }
 
-        // we'll use this later because c# doesn't support gdscript's randi()
+        // We'll use this later because C# doesn't support GDScript's randi().
         private float RandRand(float min, float max)
         {
             return (float) (rand.NextDouble() * (max - min) + min);
@@ -770,40 +770,45 @@ Note that a new instance must be added to the scene using
  .. code-tab:: gdscript GDScript
 
     func _on_MobTimer_timeout():
-        # choose a random location on Path2D
+        # Choose a random location on Path2D.
         $MobPath/MobSpawnLocation.set_offset(randi())
-        # create a Mob instance and add it to the scene
+        # Create a Mob instance and add it to the scene.
         var mob = Mob.instance()
         add_child(mob)
-        # set the mob's direction perpendicular to the path direction
-        var direction = $MobPath/MobSpawnLocation.rotation + PI/2
-        # set the mob's position to a random location
+        # Set the mob's direction perpendicular to the path direction.
+        var direction = $MobPath/MobSpawnLocation.rotation + PI / 2
+        # Set the mob's position to a random location.
         mob.position = $MobPath/MobSpawnLocation.position
-        # add some randomness to the direction
-        direction += rand_range(-PI/4, PI/4)
+        # Add some randomness to the direction.
+        direction += rand_range(-PI / 4, PI / 4)
         mob.rotation = direction
-        # choose the velocity
-        mob.set_linear_velocity(Vector2(rand_range(mob.MIN_SPEED, mob.MAX_SPEED), 0).rotated(direction))
+        # Choose the velocity.
+        mob.set_linear_velocity(Vector2(rand_range(mob.min_speed, mob.max_speed), 0).rotated(direction))
 
  .. code-tab:: csharp
 
     public void OnMobTimerTimeout()
     {
-        //choose random location on path2d
+        // Choose a random location on Path2D.
         var mobSpawnLocation = (PathFollow2D) GetNode("MobPath/MobSpawnLocation");
         mobSpawnLocation.SetOffset(rand.Next());
-    
-        //set direction
-        var direction = mobSpawnLocation.Rotation + Mathf.PI/2;
-        direction += RandRand(-Mathf.PI/4, Mathf.PI/4);
-    
-        //create mob instance and add it to scene
+
+        // Create a Mob instance and add it to the scene.
         var mobInstance = (RigidBody2D) Mob.Instance();
+        AddChild(mobInstance);
+
+        // Set the mob's direction perpendicular to the path direction.
+        var direction = mobSpawnLocation.Rotation + Mathf.PI / 2;
+
+        // Set the mob's position to a random location.
         mobInstance.Position = mobSpawnLocation.Position;
+
+        // Add some randomness to the direction.
+        direction += RandRand(-Mathf.PI / 4, Mathf.PI / 4);
         mobInstance.Rotation = direction;
+
+        // Choose the velocity.
         mobInstance.SetLinearVelocity(new Vector2(RandRand(150f, 250f), 0).Rotated(direction));
-    
-        AddChild(mobInstance);
     }
 
 .. important:: In functions requiring angles, GDScript uses *radians*,