class_sprite.rst 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the Sprite.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_Sprite:
  5. Sprite
  6. ======
  7. **Inherits:** :ref:`Node2D<class_Node2D>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
  8. **Category:** Core
  9. Brief Description
  10. -----------------
  11. General purpose Sprite node.
  12. Properties
  13. ----------
  14. +-------------------------------+---------------------------------------------------------------------+
  15. | :ref:`bool<class_bool>` | :ref:`centered<class_Sprite_property_centered>` |
  16. +-------------------------------+---------------------------------------------------------------------+
  17. | :ref:`bool<class_bool>` | :ref:`flip_h<class_Sprite_property_flip_h>` |
  18. +-------------------------------+---------------------------------------------------------------------+
  19. | :ref:`bool<class_bool>` | :ref:`flip_v<class_Sprite_property_flip_v>` |
  20. +-------------------------------+---------------------------------------------------------------------+
  21. | :ref:`int<class_int>` | :ref:`frame<class_Sprite_property_frame>` |
  22. +-------------------------------+---------------------------------------------------------------------+
  23. | :ref:`int<class_int>` | :ref:`hframes<class_Sprite_property_hframes>` |
  24. +-------------------------------+---------------------------------------------------------------------+
  25. | :ref:`Texture<class_Texture>` | :ref:`normal_map<class_Sprite_property_normal_map>` |
  26. +-------------------------------+---------------------------------------------------------------------+
  27. | :ref:`Vector2<class_Vector2>` | :ref:`offset<class_Sprite_property_offset>` |
  28. +-------------------------------+---------------------------------------------------------------------+
  29. | :ref:`bool<class_bool>` | :ref:`region_enabled<class_Sprite_property_region_enabled>` |
  30. +-------------------------------+---------------------------------------------------------------------+
  31. | :ref:`bool<class_bool>` | :ref:`region_filter_clip<class_Sprite_property_region_filter_clip>` |
  32. +-------------------------------+---------------------------------------------------------------------+
  33. | :ref:`Rect2<class_Rect2>` | :ref:`region_rect<class_Sprite_property_region_rect>` |
  34. +-------------------------------+---------------------------------------------------------------------+
  35. | :ref:`Texture<class_Texture>` | :ref:`texture<class_Sprite_property_texture>` |
  36. +-------------------------------+---------------------------------------------------------------------+
  37. | :ref:`int<class_int>` | :ref:`vframes<class_Sprite_property_vframes>` |
  38. +-------------------------------+---------------------------------------------------------------------+
  39. Methods
  40. -------
  41. +---------------------------+-----------------------------------------------------------------------------------------------------------------+
  42. | :ref:`Rect2<class_Rect2>` | :ref:`get_rect<class_Sprite_method_get_rect>` **(** **)** const |
  43. +---------------------------+-----------------------------------------------------------------------------------------------------------------+
  44. | :ref:`bool<class_bool>` | :ref:`is_pixel_opaque<class_Sprite_method_is_pixel_opaque>` **(** :ref:`Vector2<class_Vector2>` pos **)** const |
  45. +---------------------------+-----------------------------------------------------------------------------------------------------------------+
  46. Signals
  47. -------
  48. .. _class_Sprite_signal_frame_changed:
  49. - **frame_changed** **(** **)**
  50. Emitted when the :ref:`frame<class_Sprite_property_frame>` changes.
  51. .. _class_Sprite_signal_texture_changed:
  52. - **texture_changed** **(** **)**
  53. Emitted when the :ref:`texture<class_Sprite_property_texture>` changes.
  54. Description
  55. -----------
  56. A node that displays a 2D texture. The texture displayed can be a region from a larger atlas texture, or a frame from a sprite sheet animation.
  57. Property Descriptions
  58. ---------------------
  59. .. _class_Sprite_property_centered:
  60. - :ref:`bool<class_bool>` **centered**
  61. +----------+---------------------+
  62. | *Setter* | set_centered(value) |
  63. +----------+---------------------+
  64. | *Getter* | is_centered() |
  65. +----------+---------------------+
  66. If ``true``, texture is centered. Default value: ``true``.
  67. .. _class_Sprite_property_flip_h:
  68. - :ref:`bool<class_bool>` **flip_h**
  69. +----------+-------------------+
  70. | *Setter* | set_flip_h(value) |
  71. +----------+-------------------+
  72. | *Getter* | is_flipped_h() |
  73. +----------+-------------------+
  74. If ``true``, texture is flipped horizontally. Default value: ``false``.
  75. .. _class_Sprite_property_flip_v:
  76. - :ref:`bool<class_bool>` **flip_v**
  77. +----------+-------------------+
  78. | *Setter* | set_flip_v(value) |
  79. +----------+-------------------+
  80. | *Getter* | is_flipped_v() |
  81. +----------+-------------------+
  82. If ``true``, texture is flipped vertically. Default value: ``false``.
  83. .. _class_Sprite_property_frame:
  84. - :ref:`int<class_int>` **frame**
  85. +----------+------------------+
  86. | *Setter* | set_frame(value) |
  87. +----------+------------------+
  88. | *Getter* | get_frame() |
  89. +----------+------------------+
  90. Current frame to display from sprite sheet. :ref:`vframes<class_Sprite_property_vframes>` or :ref:`hframes<class_Sprite_property_hframes>` must be greater than 1.
  91. .. _class_Sprite_property_hframes:
  92. - :ref:`int<class_int>` **hframes**
  93. +----------+--------------------+
  94. | *Setter* | set_hframes(value) |
  95. +----------+--------------------+
  96. | *Getter* | get_hframes() |
  97. +----------+--------------------+
  98. The number of columns in the sprite sheet.
  99. .. _class_Sprite_property_normal_map:
  100. - :ref:`Texture<class_Texture>` **normal_map**
  101. +----------+-----------------------+
  102. | *Setter* | set_normal_map(value) |
  103. +----------+-----------------------+
  104. | *Getter* | get_normal_map() |
  105. +----------+-----------------------+
  106. The normal map gives depth to the Sprite.
  107. .. _class_Sprite_property_offset:
  108. - :ref:`Vector2<class_Vector2>` **offset**
  109. +----------+-------------------+
  110. | *Setter* | set_offset(value) |
  111. +----------+-------------------+
  112. | *Getter* | get_offset() |
  113. +----------+-------------------+
  114. The texture's drawing offset.
  115. .. _class_Sprite_property_region_enabled:
  116. - :ref:`bool<class_bool>` **region_enabled**
  117. +----------+-------------------+
  118. | *Setter* | set_region(value) |
  119. +----------+-------------------+
  120. | *Getter* | is_region() |
  121. +----------+-------------------+
  122. If ``true``, texture is cut from a larger atlas texture. See :ref:`region_rect<class_Sprite_property_region_rect>`. Default value: ``false``.
  123. .. _class_Sprite_property_region_filter_clip:
  124. - :ref:`bool<class_bool>` **region_filter_clip**
  125. +----------+---------------------------------+
  126. | *Setter* | set_region_filter_clip(value) |
  127. +----------+---------------------------------+
  128. | *Getter* | is_region_filter_clip_enabled() |
  129. +----------+---------------------------------+
  130. If ``true``, the outermost pixels get blurred out.
  131. .. _class_Sprite_property_region_rect:
  132. - :ref:`Rect2<class_Rect2>` **region_rect**
  133. +----------+------------------------+
  134. | *Setter* | set_region_rect(value) |
  135. +----------+------------------------+
  136. | *Getter* | get_region_rect() |
  137. +----------+------------------------+
  138. The region of the atlas texture to display. :ref:`region_enabled<class_Sprite_property_region_enabled>` must be ``true``.
  139. .. _class_Sprite_property_texture:
  140. - :ref:`Texture<class_Texture>` **texture**
  141. +----------+--------------------+
  142. | *Setter* | set_texture(value) |
  143. +----------+--------------------+
  144. | *Getter* | get_texture() |
  145. +----------+--------------------+
  146. :ref:`Texture<class_Texture>` object to draw.
  147. .. _class_Sprite_property_vframes:
  148. - :ref:`int<class_int>` **vframes**
  149. +----------+--------------------+
  150. | *Setter* | set_vframes(value) |
  151. +----------+--------------------+
  152. | *Getter* | get_vframes() |
  153. +----------+--------------------+
  154. The number of rows in the sprite sheet.
  155. Method Descriptions
  156. -------------------
  157. .. _class_Sprite_method_get_rect:
  158. - :ref:`Rect2<class_Rect2>` **get_rect** **(** **)** const
  159. Returns a :ref:`Rect2<class_Rect2>` representing the Sprite's boundary in local coordinates. Can be used to detect if the Sprite was clicked. Example:
  160. ::
  161. func _input(event):
  162. if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT:
  163. if get_rect().has_point(to_local(event.position)):
  164. print("A click!")
  165. .. _class_Sprite_method_is_pixel_opaque:
  166. - :ref:`bool<class_bool>` **is_pixel_opaque** **(** :ref:`Vector2<class_Vector2>` pos **)** const