Skip to content

Commit

Permalink
Play the mob animation after setting it in Your first 2D game (#10752)
Browse files Browse the repository at this point in the history
  • Loading branch information
utsav132 authored Mar 7, 2025
1 parent 996095e commit 0b174c6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions getting_started/first_2d_game/04.creating_the_enemy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ and randomly choose one of the three animation types:
func _ready():
var mob_types = Array($AnimatedSprite2D.sprite_frames.get_animation_names())
$AnimatedSprite2D.animation = mob_types.pick_random()
$AnimatedSprite2D.play()

.. code-tab:: csharp

Expand All @@ -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
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.
Connect the ``screen_exited()`` signal of the ``VisibleOnScreenNotifier2D`` node
to the ``Mob`` and add this code:
Expand Down

0 comments on commit 0b174c6

Please sign in to comment.