Files
godot-docs-l10n/classes/uk/class_animatedsprite2d.rst

448 lines
24 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:github_url: hide
.. _class_AnimatedSprite2D:
AnimatedSprite2D
================
**Успадковує:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
Вузол спрайту, який містить декілька текстур у вигляді кадрів для відтворення анімації.
.. rst-class:: classref-introduction-group
Опис
--------
Вузол **AnimatedSprite2D** подібний до вузла :ref:`Sprite2D<class_Sprite2D>`, за винятком того, що він містить декілька текстур в якості кадрів анімації. Анімація створюється за допомогою ресурсу :ref:`SpriteFrames<class_SpriteFrames>`, який дозволяє імпортувати файли зображень (або папку з цими файлами) для створення кадрів анімації для спрайту. Ресурс :ref:`SpriteFrames<class_SpriteFrames>` можна налаштувати у редакторі за допомогою нижньої панелі SpriteFrames.
.. rst-class:: classref-introduction-group
Посібники
------------------
- :doc:`Анімація 2D спрайтів <../tutorials/2d/2d_sprite_animation>`
- `2D демонстрація Dodge The Creeps <https://godotengine.org/asset-library/asset/2712>`__
.. rst-class:: classref-reftable-group
Властивості
----------------------
.. table::
:widths: auto
+-----------------------------------------+-----------------------------------------------------------------------+-------------------+
| :ref:`StringName<class_StringName>` | :ref:`animation<class_AnimatedSprite2D_property_animation>` | ``&"default"`` |
+-----------------------------------------+-----------------------------------------------------------------------+-------------------+
| :ref:`String<class_String>` | :ref:`autoplay<class_AnimatedSprite2D_property_autoplay>` | ``""`` |
+-----------------------------------------+-----------------------------------------------------------------------+-------------------+
| :ref:`bool<class_bool>` | :ref:`centered<class_AnimatedSprite2D_property_centered>` | ``true`` |
+-----------------------------------------+-----------------------------------------------------------------------+-------------------+
| :ref:`bool<class_bool>` | :ref:`flip_h<class_AnimatedSprite2D_property_flip_h>` | ``false`` |
+-----------------------------------------+-----------------------------------------------------------------------+-------------------+
| :ref:`bool<class_bool>` | :ref:`flip_v<class_AnimatedSprite2D_property_flip_v>` | ``false`` |
+-----------------------------------------+-----------------------------------------------------------------------+-------------------+
| :ref:`int<class_int>` | :ref:`frame<class_AnimatedSprite2D_property_frame>` | ``0`` |
+-----------------------------------------+-----------------------------------------------------------------------+-------------------+
| :ref:`float<class_float>` | :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` | ``0.0`` |
+-----------------------------------------+-----------------------------------------------------------------------+-------------------+
| :ref:`Vector2<class_Vector2>` | :ref:`offset<class_AnimatedSprite2D_property_offset>` | ``Vector2(0, 0)`` |
+-----------------------------------------+-----------------------------------------------------------------------+-------------------+
| :ref:`float<class_float>` | :ref:`speed_scale<class_AnimatedSprite2D_property_speed_scale>` | ``1.0`` |
+-----------------------------------------+-----------------------------------------------------------------------+-------------------+
| :ref:`SpriteFrames<class_SpriteFrames>` | :ref:`sprite_frames<class_AnimatedSprite2D_property_sprite_frames>` | |
+-----------------------------------------+-----------------------------------------------------------------------+-------------------+
.. rst-class:: classref-reftable-group
Методи
------------
.. table::
:widths: auto
+---------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`get_playing_speed<class_AnimatedSprite2D_method_get_playing_speed>`\ (\ ) |const| |
+---------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`is_playing<class_AnimatedSprite2D_method_is_playing>`\ (\ ) |const| |
+---------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`pause<class_AnimatedSprite2D_method_pause>`\ (\ ) |
+---------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`play<class_AnimatedSprite2D_method_play>`\ (\ name\: :ref:`StringName<class_StringName>` = &"", custom_speed\: :ref:`float<class_float>` = 1.0, from_end\: :ref:`bool<class_bool>` = false\ ) |
+---------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`play_backwards<class_AnimatedSprite2D_method_play_backwards>`\ (\ name\: :ref:`StringName<class_StringName>` = &""\ ) |
+---------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`set_frame_and_progress<class_AnimatedSprite2D_method_set_frame_and_progress>`\ (\ frame\: :ref:`int<class_int>`, progress\: :ref:`float<class_float>`\ ) |
+---------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`stop<class_AnimatedSprite2D_method_stop>`\ (\ ) |
+---------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Сигнали
--------------
.. _class_AnimatedSprite2D_signal_animation_changed:
.. rst-class:: classref-signal
**animation_changed**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_signal_animation_changed>`
Випромінюється, коли змінюється :ref:`animation<class_AnimatedSprite2D_property_animation>`.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_signal_animation_finished:
.. rst-class:: classref-signal
**animation_finished**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_signal_animation_finished>`
Видається, коли анімація досягає кінця або початку, якщо вона відтворюється у зворотному напрямку. Після завершення анімації відтворення призупиняється.
\ **Примітка.** Цей сигнал не випромінюється, якщо анімація повторюється.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_signal_animation_looped:
.. rst-class:: classref-signal
**animation_looped**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_signal_animation_looped>`
Випромінюється, коли анімація повторюється.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_signal_frame_changed:
.. rst-class:: classref-signal
**frame_changed**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_signal_frame_changed>`
Випромінюється, коли змінюється :ref:`frame<class_AnimatedSprite2D_property_frame>`.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_signal_sprite_frames_changed:
.. rst-class:: classref-signal
**sprite_frames_changed**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_signal_sprite_frames_changed>`
Випромінюється, коли змінюється :ref:`sprite_frames<class_AnimatedSprite2D_property_sprite_frames>`.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Описи властивостей
------------------------------------
.. _class_AnimatedSprite2D_property_animation:
.. rst-class:: classref-property
:ref:`StringName<class_StringName>` **animation** = ``&"default"`` :ref:`🔗<class_AnimatedSprite2D_property_animation>`
.. rst-class:: classref-property-setget
- |void| **set_animation**\ (\ value\: :ref:`StringName<class_StringName>`\ )
- :ref:`StringName<class_StringName>` **get_animation**\ (\ )
Поточна анімація з ресурсу :ref:`sprite_frames<class_AnimatedSprite2D_property_sprite_frames>`. Якщо це значення змінюється, лічильник :ref:`frame<class_AnimatedSprite2D_property_frame>` та :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` обнуляються.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_property_autoplay:
.. rst-class:: classref-property
:ref:`String<class_String>` **autoplay** = ``""`` :ref:`🔗<class_AnimatedSprite2D_property_autoplay>`
.. rst-class:: classref-property-setget
- |void| **set_autoplay**\ (\ value\: :ref:`String<class_String>`\ )
- :ref:`String<class_String>` **get_autoplay**\ (\ )
Ключ анімації для відтворення при завантаженні сцени.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_property_centered:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **centered** = ``true`` :ref:`🔗<class_AnimatedSprite2D_property_centered>`
.. rst-class:: classref-property-setget
- |void| **set_centered**\ (\ value\: :ref:`bool<class_bool>`\ )
- :ref:`bool<class_bool>` **is_centered**\ (\ )
Якщо ``true``, текстура буде відцентрована.
\ **Примітка.** В іграх із естетикою піксельного мистецтва текстури можуть виглядати деформованими, якщо їх центрувати. Це викликано їх розташуванням між пікселями. Щоб запобігти цьому, установіть для цієї властивості значення ``false`` або спробуйте ввімкнути :ref:`ProjectSettings.rendering/2d/snap/snap_2d_vertices_to_pixel<class_ProjectSettings_property_rendering/2d/snap/snap_2d_vertices_to_pixel>` і :ref:`ProjectSettings.rendering/2d/snap/snap_2d_transforms_to_pixel<class_ProjectSettings_property_rendering/2d/snap/snap_2d_transforms_to_pixel>`.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_property_flip_h:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **flip_h** = ``false`` :ref:`🔗<class_AnimatedSprite2D_property_flip_h>`
.. rst-class:: classref-property-setget
- |void| **set_flip_h**\ (\ value\: :ref:`bool<class_bool>`\ )
- :ref:`bool<class_bool>` **is_flipped_h**\ (\ )
Якщо ``true``, текстура віддзеркалюється горизонтально.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_property_flip_v:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **flip_v** = ``false`` :ref:`🔗<class_AnimatedSprite2D_property_flip_v>`
.. rst-class:: classref-property-setget
- |void| **set_flip_v**\ (\ value\: :ref:`bool<class_bool>`\ )
- :ref:`bool<class_bool>` **is_flipped_v**\ (\ )
Якщо ``true``, текстура віддзеркалюється вертикально.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_property_frame:
.. rst-class:: classref-property
:ref:`int<class_int>` **frame** = ``0`` :ref:`🔗<class_AnimatedSprite2D_property_frame>`
.. rst-class:: classref-property-setget
- |void| **set_frame**\ (\ value\: :ref:`int<class_int>`\ )
- :ref:`int<class_int>` **get_frame**\ (\ )
Індекс відображуваного кадру анімації. Встановлення цієї властивості також скидає :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>`. Якщо це не бажано, використовуйте :ref:`set_frame_and_progress()<class_AnimatedSprite2D_method_set_frame_and_progress>`.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_property_frame_progress:
.. rst-class:: classref-property
:ref:`float<class_float>` **frame_progress** = ``0.0`` :ref:`🔗<class_AnimatedSprite2D_property_frame_progress>`
.. rst-class:: classref-property-setget
- |void| **set_frame_progress**\ (\ value\: :ref:`float<class_float>`\ )
- :ref:`float<class_float>` **get_frame_progress**\ (\ )
Значення прогресу між ``0.0`` і ``1.0`` до моменту переходу до наступного кадру. Якщо анімація відтворюється у зворотному напрямку, значення переходить від ``1.0`` до ``0.0``.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_property_offset:
.. rst-class:: classref-property
:ref:`Vector2<class_Vector2>` **offset** = ``Vector2(0, 0)`` :ref:`🔗<class_AnimatedSprite2D_property_offset>`
.. rst-class:: classref-property-setget
- |void| **set_offset**\ (\ value\: :ref:`Vector2<class_Vector2>`\ )
- :ref:`Vector2<class_Vector2>` **get_offset**\ (\ )
Зміщення малюнка текстури.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_property_speed_scale:
.. rst-class:: classref-property
:ref:`float<class_float>` **speed_scale** = ``1.0`` :ref:`🔗<class_AnimatedSprite2D_property_speed_scale>`
.. rst-class:: classref-property-setget
- |void| **set_speed_scale**\ (\ value\: :ref:`float<class_float>`\ )
- :ref:`float<class_float>` **get_speed_scale**\ (\ )
Коефіцієнт масштабування швидкості. Наприклад, якщо це значення ``1``, то анімація відтворюється з нормальною швидкістю. Якщо це ``0.5``, то вона відтворюється наполовину швидко. Якщо це ``2``, то анімація відтворюється з подвійною швидкістю.
Якщо встановлено від'ємне значення, анімація відтворюється у зворотному напрямку. Якщо встановлено ``0``, анімація не буде відтворюватися.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_property_sprite_frames:
.. rst-class:: classref-property
:ref:`SpriteFrames<class_SpriteFrames>` **sprite_frames** :ref:`🔗<class_AnimatedSprite2D_property_sprite_frames>`
.. rst-class:: classref-property-setget
- |void| **set_sprite_frames**\ (\ value\: :ref:`SpriteFrames<class_SpriteFrames>`\ )
- :ref:`SpriteFrames<class_SpriteFrames>` **get_sprite_frames**\ (\ )
Ресурс :ref:`SpriteFrames<class_SpriteFrames>`, що містить анімацію(ї). Дозволяє завантажувати, редагувати, очищати, робити унікальними та зберігати стани ресурсу :ref:`SpriteFrames<class_SpriteFrames>`.
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Описи методів
--------------------------
.. _class_AnimatedSprite2D_method_get_playing_speed:
.. rst-class:: classref-method
:ref:`float<class_float>` **get_playing_speed**\ (\ ) |const| :ref:`🔗<class_AnimatedSprite2D_method_get_playing_speed>`
Повертає фактичну швидкість відтворення поточної анімації або ``0``, якщо вона не відтворюється. Ця швидкість - це властивість :ref:`speed_scale<class_AnimatedSprite2D_property_speed_scale>`, помножена на аргумент ``custom_speed``, вказаний при виклику методу :ref:`play()<class_AnimatedSprite2D_method_play>`.
Повертає від'ємне значення, якщо поточна анімація відтворюється у зворотному напрямку.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_method_is_playing:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **is_playing**\ (\ ) |const| :ref:`🔗<class_AnimatedSprite2D_method_is_playing>`
Повертає ``true``, якщо анімація зараз відтворюється (навіть якщо :ref:`speed_scale<class_AnimatedSprite2D_property_speed_scale>` та/або ``custom_speed`` рівні ``0``).
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_method_pause:
.. rst-class:: classref-method
|void| **pause**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_method_pause>`
Ставить на паузу анімацію, що відтворюється у даний момент. Кадри :ref:`frame<class_AnimatedSprite2D_property_frame>` і :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` будуть збережені, а виклик :ref:`play()<class_AnimatedSprite2D_method_play>`, або :ref:`play_backwards()<class_AnimatedSprite2D_method_play_backwards>`, без аргументів, відновить анімацію з поточної позиції відтворення.
Дивіться також :ref:`stop()<class_AnimatedSprite2D_method_stop>`.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_method_play:
.. rst-class:: classref-method
|void| **play**\ (\ name\: :ref:`StringName<class_StringName>` = &"", custom_speed\: :ref:`float<class_float>` = 1.0, from_end\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_AnimatedSprite2D_method_play>`
Відтворює анімацію з ключем ``name``. Якщо ``custom_speed`` від'ємний, а ``from_end`` має значення ``true``, анімація буде відтворюватися у зворотному напрямку (що еквівалентно виклику :ref:`play_backwards()<class_AnimatedSprite2D_method_play_backwards>`).
Якщо цей метод викликати з тією самою анімацією ``name`` або без параметра ``name``, призначена анімація відновить відтворення, якщо її було призупинено.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_method_play_backwards:
.. rst-class:: classref-method
|void| **play_backwards**\ (\ name\: :ref:`StringName<class_StringName>` = &""\ ) :ref:`🔗<class_AnimatedSprite2D_method_play_backwards>`
Відтворює анімацію з ключем ``name`` у зворотному напрямку.
Цей метод є скороченням від :ref:`play()<class_AnimatedSprite2D_method_play>` з ``custom_speed = -1.0`` і ``from_end = true``, тому дивіться його опис для додаткової інформації.
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_method_set_frame_and_progress:
.. rst-class:: classref-method
|void| **set_frame_and_progress**\ (\ frame\: :ref:`int<class_int>`, progress\: :ref:`float<class_float>`\ ) :ref:`🔗<class_AnimatedSprite2D_method_set_frame_and_progress>`
Встановлює для :ref:`frame<class_AnimatedSprite2D_property_frame>` та :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` задані значення. На відміну від встановлення :ref:`frame<class_AnimatedSprite2D_property_frame>`, цей метод не скидає :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>` до ``0.0`` неявно.
\ **Приклад:** Змініть анімацію, зберігаючи ті самі :ref:`frame<class_AnimatedSprite2D_property_frame>` та :ref:`frame_progress<class_AnimatedSprite2D_property_frame_progress>`:
.. tabs::
.. code-tab:: gdscript
var current_frame = animated_sprite.get_frame()
var current_progress = animated_sprite.get_frame_progress()
animated_sprite.play("walk_another_skin")
animated_sprite.set_frame_and_progress(current_frame, current_progress)
.. rst-class:: classref-item-separator
----
.. _class_AnimatedSprite2D_method_stop:
.. rst-class:: classref-method
|void| **stop**\ (\ ) :ref:`🔗<class_AnimatedSprite2D_method_stop>`
Зупиняє відтворення поточної анімації. Позицію анімації буде скинуто до ``0``, а ``custom_speed`` до ``1.0``. Дивіться також :ref:`pause()<class_AnimatedSprite2D_method_pause>`.
.. |virtual| replace:: :abbr:`virtual (Зазвичай, цей метод перевизначається користувачем, щоб він мав вплив.)`
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
.. |const| replace:: :abbr:`const (Цей метод не має побічних ефектів. Не змінює ніяку змінну екземпляра об'єкта.)`
.. |vararg| replace:: :abbr:`vararg (Цей метод приймає будь-яке число аргументів після описаних тут.)`
.. |constructor| replace:: :abbr:`constructor (Цей метод використовується для побудови типів.)`
.. |static| replace:: :abbr:`static (Цей метод не потребує екземпляра для виклику, його можна викликати безпосередньо за допомогою назви класу.)`
.. |operator| replace:: :abbr:`operator (Цей метод описує дійсний оператор для взаємодії з цим типом як з лівим операндом.)`
.. |bitfield| replace:: :abbr:`BitField (Це значення є цілим числом, складеним у вигляді бітової маски з наступних прапорів.)`
.. |void| replace:: :abbr:`void (Значення не повертається.)`