Skip to content

Commit 0b174c6

Browse files
authored
Play the mob animation after setting it in Your first 2D game (#10752)
1 parent 996095e commit 0b174c6

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

getting_started/first_2d_game/04.creating_the_enemy.rst

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ and randomly choose one of the three animation types:
8787
func _ready():
8888
var mob_types = Array($AnimatedSprite2D.sprite_frames.get_animation_names())
8989
$AnimatedSprite2D.animation = mob_types.pick_random()
90+
$AnimatedSprite2D.play()
9091

9192
.. code-tab:: csharp
9293

@@ -106,6 +107,8 @@ to select one of these animation names at random. Meanwhile, in the C# code, we
106107
between ``0`` and ``2`` to select one of these names from the list (array indices start at ``0``). The
107108
expression ``GD.Randi() % n`` selects a random integer between ``0`` and ``n-1``.
108109

110+
Finally, we call ``play()`` to start playing the chosen animation.
111+
109112
The last piece is to make the mobs delete themselves when they leave the screen.
110113
Connect the ``screen_exited()`` signal of the ``VisibleOnScreenNotifier2D`` node
111114
to the ``Mob`` and add this code:

0 commit comments

Comments
 (0)