Browse Source

Play the mob animation after setting it in Your first 2D game (#10752)

utsav132 7 months ago
parent
commit
0b174c6df3
1 changed files with 3 additions and 0 deletions
  1. 3 0
      getting_started/first_2d_game/04.creating_the_enemy.rst

+ 3 - 0
getting_started/first_2d_game/04.creating_the_enemy.rst

@@ -87,6 +87,7 @@ and randomly choose one of the three animation types:
     func _ready():
     func _ready():
         var mob_types = Array($AnimatedSprite2D.sprite_frames.get_animation_names())
         var mob_types = Array($AnimatedSprite2D.sprite_frames.get_animation_names())
         $AnimatedSprite2D.animation = mob_types.pick_random()
         $AnimatedSprite2D.animation = mob_types.pick_random()
+        $AnimatedSprite2D.play()
 
 
  .. code-tab:: csharp
  .. code-tab:: csharp
 
 
@@ -106,6 +107,8 @@ to select one of these animation names at random. Meanwhile, in the C# code, we
 between ``0`` and ``2`` to select one of these names from the list (array indices start at ``0``). The 
 between ``0`` and ``2`` to select one of these names from the list (array indices start at ``0``). The 
 expression ``GD.Randi() % n`` selects a random integer between ``0`` and ``n-1``.
 expression ``GD.Randi() % n`` selects a random integer between ``0`` and ``n-1``.
 
 
+Finally, we call ``play()`` to start playing the chosen animation.
+
 The last piece is to make the mobs delete themselves when they leave the screen.
 The last piece is to make the mobs delete themselves when they leave the screen.
 Connect the ``screen_exited()`` signal of the ``VisibleOnScreenNotifier2D`` node
 Connect the ``screen_exited()`` signal of the ``VisibleOnScreenNotifier2D`` node
 to the ``Mob`` and add this code:
 to the ``Mob`` and add this code: