From 8596ceb332cc128406f73c851601434ebdc349ff Mon Sep 17 00:00:00 2001 From: utsav132 <155137203+utsav132@users.noreply.github.com> Date: Fri, 7 Mar 2025 01:27:30 +0530 Subject: [PATCH 1/2] Added script to play the mob animation Added script to play the mob animation, along with its explanation in the docs. --- getting_started/first_2d_game/04.creating_the_enemy.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/getting_started/first_2d_game/04.creating_the_enemy.rst b/getting_started/first_2d_game/04.creating_the_enemy.rst index af11ba167e7..133c8a4c3f9 100644 --- a/getting_started/first_2d_game/04.creating_the_enemy.rst +++ b/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(): var mob_types = Array($AnimatedSprite2D.sprite_frames.get_animation_names()) $AnimatedSprite2D.animation = mob_types.pick_random() + $AnimatedSprite2D.play() .. 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 expression ``GD.Randi() % n`` selects a random integer between ``0`` and ``n-1``. +Finally, we call $AnimatedSprite2D.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: From 4fa0275342611abac5d7397ab890bee34ff85235 Mon Sep 17 00:00:00 2001 From: utsav132 <155137203+utsav132@users.noreply.github.com> Date: Fri, 7 Mar 2025 01:40:47 +0530 Subject: [PATCH 2/2] Improved in docs for playing mob animation --- getting_started/first_2d_game/04.creating_the_enemy.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting_started/first_2d_game/04.creating_the_enemy.rst b/getting_started/first_2d_game/04.creating_the_enemy.rst index 133c8a4c3f9..3260477aef2 100644 --- a/getting_started/first_2d_game/04.creating_the_enemy.rst +++ b/getting_started/first_2d_game/04.creating_the_enemy.rst @@ -107,7 +107,7 @@ 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 $AnimatedSprite2D.play() to start playing the chosen animation. +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