Files
godot-docs/classes/class_spriteframes.rst
2023-07-24 10:19:30 +00:00

290 lines
17 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/4.1/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/4.1/doc/classes/SpriteFrames.xml.
.. _class_SpriteFrames:
SpriteFrames
============
**Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
Sprite frame library for AnimatedSprite2D and AnimatedSprite3D.
.. rst-class:: classref-introduction-group
Description
-----------
Sprite frame library for an :ref:`AnimatedSprite2D<class_AnimatedSprite2D>` or :ref:`AnimatedSprite3D<class_AnimatedSprite3D>` node. Contains frames and animation data for playback.
.. rst-class:: classref-reftable-group
Methods
-------
.. table::
:widths: auto
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`add_animation<class_SpriteFrames_method_add_animation>` **(** :ref:`StringName<class_StringName>` anim **)** |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`add_frame<class_SpriteFrames_method_add_frame>` **(** :ref:`StringName<class_StringName>` anim, :ref:`Texture2D<class_Texture2D>` texture, :ref:`float<class_float>` duration=1.0, :ref:`int<class_int>` at_position=-1 **)** |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`clear<class_SpriteFrames_method_clear>` **(** :ref:`StringName<class_StringName>` anim **)** |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`clear_all<class_SpriteFrames_method_clear_all>` **(** **)** |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`get_animation_loop<class_SpriteFrames_method_get_animation_loop>` **(** :ref:`StringName<class_StringName>` anim **)** |const| |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_animation_names<class_SpriteFrames_method_get_animation_names>` **(** **)** |const| |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`get_animation_speed<class_SpriteFrames_method_get_animation_speed>` **(** :ref:`StringName<class_StringName>` anim **)** |const| |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_frame_count<class_SpriteFrames_method_get_frame_count>` **(** :ref:`StringName<class_StringName>` anim **)** |const| |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`get_frame_duration<class_SpriteFrames_method_get_frame_duration>` **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)** |const| |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Texture2D<class_Texture2D>` | :ref:`get_frame_texture<class_SpriteFrames_method_get_frame_texture>` **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)** |const| |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`has_animation<class_SpriteFrames_method_has_animation>` **(** :ref:`StringName<class_StringName>` anim **)** |const| |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`remove_animation<class_SpriteFrames_method_remove_animation>` **(** :ref:`StringName<class_StringName>` anim **)** |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`remove_frame<class_SpriteFrames_method_remove_frame>` **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)** |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`rename_animation<class_SpriteFrames_method_rename_animation>` **(** :ref:`StringName<class_StringName>` anim, :ref:`StringName<class_StringName>` newname **)** |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_animation_loop<class_SpriteFrames_method_set_animation_loop>` **(** :ref:`StringName<class_StringName>` anim, :ref:`bool<class_bool>` loop **)** |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_animation_speed<class_SpriteFrames_method_set_animation_speed>` **(** :ref:`StringName<class_StringName>` anim, :ref:`float<class_float>` fps **)** |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`set_frame<class_SpriteFrames_method_set_frame>` **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx, :ref:`Texture2D<class_Texture2D>` texture, :ref:`float<class_float>` duration=1.0 **)** |
+---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Method Descriptions
-------------------
.. _class_SpriteFrames_method_add_animation:
.. rst-class:: classref-method
void **add_animation** **(** :ref:`StringName<class_StringName>` anim **)**
Adds a new ``anim`` animation to the library.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_add_frame:
.. rst-class:: classref-method
void **add_frame** **(** :ref:`StringName<class_StringName>` anim, :ref:`Texture2D<class_Texture2D>` texture, :ref:`float<class_float>` duration=1.0, :ref:`int<class_int>` at_position=-1 **)**
Adds a frame to the ``anim`` animation. If ``at_position`` is ``-1``, the frame will be added to the end of the animation.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_clear:
.. rst-class:: classref-method
void **clear** **(** :ref:`StringName<class_StringName>` anim **)**
Removes all frames from the ``anim`` animation.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_clear_all:
.. rst-class:: classref-method
void **clear_all** **(** **)**
Removes all animations. An empty ``default`` animation will be created.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_get_animation_loop:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **get_animation_loop** **(** :ref:`StringName<class_StringName>` anim **)** |const|
Returns ``true`` if the given animation is configured to loop when it finishes playing. Otherwise, returns ``false``.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_get_animation_names:
.. rst-class:: classref-method
:ref:`PackedStringArray<class_PackedStringArray>` **get_animation_names** **(** **)** |const|
Returns an array containing the names associated to each animation. Values are placed in alphabetical order.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_get_animation_speed:
.. rst-class:: classref-method
:ref:`float<class_float>` **get_animation_speed** **(** :ref:`StringName<class_StringName>` anim **)** |const|
Returns the speed in frames per second for the ``anim`` animation.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_get_frame_count:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_frame_count** **(** :ref:`StringName<class_StringName>` anim **)** |const|
Returns the number of frames for the ``anim`` animation.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_get_frame_duration:
.. rst-class:: classref-method
:ref:`float<class_float>` **get_frame_duration** **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)** |const|
Returns a relative duration of the frame ``idx`` in the ``anim`` animation (defaults to ``1.0``). For example, a frame with a duration of ``2.0`` is displayed twice as long as a frame with a duration of ``1.0``. You can calculate the absolute duration (in seconds) of a frame using the following formula:
::
absolute_duration = relative_duration / (animation_fps * abs(playing_speed))
In this example, ``playing_speed`` refers to either :ref:`AnimatedSprite2D.get_playing_speed<class_AnimatedSprite2D_method_get_playing_speed>` or :ref:`AnimatedSprite3D.get_playing_speed<class_AnimatedSprite3D_method_get_playing_speed>`.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_get_frame_texture:
.. rst-class:: classref-method
:ref:`Texture2D<class_Texture2D>` **get_frame_texture** **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)** |const|
Returns the texture of the frame ``idx`` in the ``anim`` animation.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_has_animation:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **has_animation** **(** :ref:`StringName<class_StringName>` anim **)** |const|
Returns ``true`` if the ``anim`` animation exists.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_remove_animation:
.. rst-class:: classref-method
void **remove_animation** **(** :ref:`StringName<class_StringName>` anim **)**
Removes the ``anim`` animation.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_remove_frame:
.. rst-class:: classref-method
void **remove_frame** **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx **)**
Removes the ``anim`` animation's frame ``idx``.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_rename_animation:
.. rst-class:: classref-method
void **rename_animation** **(** :ref:`StringName<class_StringName>` anim, :ref:`StringName<class_StringName>` newname **)**
Changes the ``anim`` animation's name to ``newname``.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_set_animation_loop:
.. rst-class:: classref-method
void **set_animation_loop** **(** :ref:`StringName<class_StringName>` anim, :ref:`bool<class_bool>` loop **)**
If ``loop`` is ``true``, the ``anim`` animation will loop when it reaches the end, or the start if it is played in reverse.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_set_animation_speed:
.. rst-class:: classref-method
void **set_animation_speed** **(** :ref:`StringName<class_StringName>` anim, :ref:`float<class_float>` fps **)**
Sets the speed for the ``anim`` animation in frames per second.
.. rst-class:: classref-item-separator
----
.. _class_SpriteFrames_method_set_frame:
.. rst-class:: classref-method
void **set_frame** **(** :ref:`StringName<class_StringName>` anim, :ref:`int<class_int>` idx, :ref:`Texture2D<class_Texture2D>` texture, :ref:`float<class_float>` duration=1.0 **)**
Sets the ``texture`` and the ``duration`` of the frame ``idx`` in the ``anim`` animation.
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
.. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`