class_animatedtexture.rst 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the AnimatedTexture.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_AnimatedTexture:
  6. AnimatedTexture
  7. ===============
  8. **Inherits:** :ref:`Texture<class_Texture>` **<** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  9. Proxy texture for simple frame-based animations.
  10. Description
  11. -----------
  12. ``AnimatedTexture`` is a resource format for frame-based animations, where multiple textures can be chained automatically with a predefined delay for each frame. Unlike :ref:`AnimationPlayer<class_AnimationPlayer>` or :ref:`AnimatedSprite<class_AnimatedSprite>`, it isn't a :ref:`Node<class_Node>`, but has the advantage of being usable anywhere a :ref:`Texture<class_Texture>` resource can be used, e.g. in a :ref:`TileSet<class_TileSet>`.
  13. The playback of the animation is controlled by the :ref:`fps<class_AnimatedTexture_property_fps>` property as well as each frame's optional delay (see :ref:`set_frame_delay<class_AnimatedTexture_method_set_frame_delay>`). The animation loops, i.e. it will restart at frame 0 automatically after playing the last frame.
  14. ``AnimatedTexture`` currently requires all frame textures to have the same size, otherwise the bigger ones will be cropped to match the smallest one. Also, it doesn't support :ref:`AtlasTexture<class_AtlasTexture>`. Each frame needs to be separate image.
  15. Properties
  16. ----------
  17. +---------------------------+------------------------------------------------------+----------+
  18. | :ref:`int<class_int>` | flags | **O:** 0 |
  19. +---------------------------+------------------------------------------------------+----------+
  20. | :ref:`float<class_float>` | :ref:`fps<class_AnimatedTexture_property_fps>` | 4.0 |
  21. +---------------------------+------------------------------------------------------+----------+
  22. | :ref:`int<class_int>` | :ref:`frames<class_AnimatedTexture_property_frames>` | 1 |
  23. +---------------------------+------------------------------------------------------+----------+
  24. Methods
  25. -------
  26. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  27. | :ref:`float<class_float>` | :ref:`get_frame_delay<class_AnimatedTexture_method_get_frame_delay>` **(** :ref:`int<class_int>` frame **)** const |
  28. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  29. | :ref:`Texture<class_Texture>` | :ref:`get_frame_texture<class_AnimatedTexture_method_get_frame_texture>` **(** :ref:`int<class_int>` frame **)** const |
  30. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | void | :ref:`set_frame_delay<class_AnimatedTexture_method_set_frame_delay>` **(** :ref:`int<class_int>` frame, :ref:`float<class_float>` delay **)** |
  32. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | void | :ref:`set_frame_texture<class_AnimatedTexture_method_set_frame_texture>` **(** :ref:`int<class_int>` frame, :ref:`Texture<class_Texture>` texture **)** |
  34. +-------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. Constants
  36. ---------
  37. .. _class_AnimatedTexture_constant_MAX_FRAMES:
  38. - **MAX_FRAMES** = **256** --- The maximum number of frames supported by ``AnimatedTexture``. If you need more frames in your animation, use :ref:`AnimationPlayer<class_AnimationPlayer>` or :ref:`AnimatedSprite<class_AnimatedSprite>`.
  39. Property Descriptions
  40. ---------------------
  41. .. _class_AnimatedTexture_property_fps:
  42. - :ref:`float<class_float>` **fps**
  43. +-----------+----------------+
  44. | *Default* | 4.0 |
  45. +-----------+----------------+
  46. | *Setter* | set_fps(value) |
  47. +-----------+----------------+
  48. | *Getter* | get_fps() |
  49. +-----------+----------------+
  50. Animation speed in frames per second. This value defines the default time interval between two frames of the animation, and thus the overall duration of the animation loop based on the :ref:`frames<class_AnimatedTexture_property_frames>` property. A value of 0 means no predefined number of frames per second, the animation will play according to each frame's frame delay (see :ref:`set_frame_delay<class_AnimatedTexture_method_set_frame_delay>`).
  51. For example, an animation with 8 frames, no frame delay and a ``fps`` value of 2 will run for 4 seconds, with each frame lasting 0.5 seconds.
  52. ----
  53. .. _class_AnimatedTexture_property_frames:
  54. - :ref:`int<class_int>` **frames**
  55. +-----------+-------------------+
  56. | *Default* | 1 |
  57. +-----------+-------------------+
  58. | *Setter* | set_frames(value) |
  59. +-----------+-------------------+
  60. | *Getter* | get_frames() |
  61. +-----------+-------------------+
  62. Number of frames to use in the animation. While you can create the frames independently with :ref:`set_frame_texture<class_AnimatedTexture_method_set_frame_texture>`, you need to set this value for the animation to take new frames into account. The maximum number of frames is :ref:`MAX_FRAMES<class_AnimatedTexture_constant_MAX_FRAMES>`.
  63. Method Descriptions
  64. -------------------
  65. .. _class_AnimatedTexture_method_get_frame_delay:
  66. - :ref:`float<class_float>` **get_frame_delay** **(** :ref:`int<class_int>` frame **)** const
  67. Returns the given frame's delay value.
  68. ----
  69. .. _class_AnimatedTexture_method_get_frame_texture:
  70. - :ref:`Texture<class_Texture>` **get_frame_texture** **(** :ref:`int<class_int>` frame **)** const
  71. Returns the given frame's :ref:`Texture<class_Texture>`.
  72. ----
  73. .. _class_AnimatedTexture_method_set_frame_delay:
  74. - void **set_frame_delay** **(** :ref:`int<class_int>` frame, :ref:`float<class_float>` delay **)**
  75. Sets an additional delay (in seconds) between this frame and the next one, that will be added to the time interval defined by :ref:`fps<class_AnimatedTexture_property_fps>`. By default, frames have no delay defined. If a delay value is defined, the final time interval between this frame and the next will be ``1.0 / fps + delay``.
  76. For example, for an animation with 3 frames, 2 FPS and a frame delay on the second frame of 1.2, the resulting playback will be:
  77. ::
  78. Frame 0: 0.5 s (1 / fps)
  79. Frame 1: 1.7 s (1 / fps + 1.2)
  80. Frame 2: 0.5 s (1 / fps)
  81. Total duration: 2.7 s
  82. ----
  83. .. _class_AnimatedTexture_method_set_frame_texture:
  84. - void **set_frame_texture** **(** :ref:`int<class_int>` frame, :ref:`Texture<class_Texture>` texture **)**
  85. Assigns a :ref:`Texture<class_Texture>` to the given frame. Frame IDs start at 0, so the first frame has ID 0, and the last frame of the animation has ID :ref:`frames<class_AnimatedTexture_property_frames>` - 1.
  86. You can define any number of textures up to :ref:`MAX_FRAMES<class_AnimatedTexture_constant_MAX_FRAMES>`, but keep in mind that only frames from 0 to :ref:`frames<class_AnimatedTexture_property_frames>` - 1 will be part of the animation.