Files
godot-docs-l10n/classes/zh_Hant/class_texturebutton.rst

315 lines
14 KiB
ReStructuredText

:github_url: hide
.. _class_TextureButton:
TextureButton
=============
**繼承:** :ref:`BaseButton<class_BaseButton>` **<** :ref:`Control<class_Control>` **<** :ref:`CanvasItem<class_CanvasItem>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
基於紋理的按鈕。支援按下、懸停、停用和焦點狀態。
.. rst-class:: classref-introduction-group
說明
----
**TextureButton** has the same functionality as :ref:`Button<class_Button>`, except it uses sprites instead of Godot's :ref:`Theme<class_Theme>` resource. It is faster to create, but it doesn't support localization like more complex :ref:`Control<class_Control>`\ s.
See also :ref:`BaseButton<class_BaseButton>` which contains common properties and methods associated with this node.
\ **Note:** Setting a texture for the "normal" state (:ref:`texture_normal<class_TextureButton_property_texture_normal>`) is recommended. If :ref:`texture_normal<class_TextureButton_property_texture_normal>` is not set, the **TextureButton** will still receive input events and be clickable, but the user will not be able to see it unless they activate another one of its states with a texture assigned (e.g., hover over it to show :ref:`texture_hover<class_TextureButton_property_texture_hover>`).
.. rst-class:: classref-introduction-group
教學
----
- `3D 體素示範 <https://godotengine.org/asset-library/asset/2755>`__
.. rst-class:: classref-reftable-group
屬性
----
.. table::
:widths: auto
+----------------------------------------------------+------------------------------------------------------------------------------+-----------+
| :ref:`bool<class_bool>` | :ref:`flip_h<class_TextureButton_property_flip_h>` | ``false`` |
+----------------------------------------------------+------------------------------------------------------------------------------+-----------+
| :ref:`bool<class_bool>` | :ref:`flip_v<class_TextureButton_property_flip_v>` | ``false`` |
+----------------------------------------------------+------------------------------------------------------------------------------+-----------+
| :ref:`bool<class_bool>` | :ref:`ignore_texture_size<class_TextureButton_property_ignore_texture_size>` | ``false`` |
+----------------------------------------------------+------------------------------------------------------------------------------+-----------+
| :ref:`StretchMode<enum_TextureButton_StretchMode>` | :ref:`stretch_mode<class_TextureButton_property_stretch_mode>` | ``2`` |
+----------------------------------------------------+------------------------------------------------------------------------------+-----------+
| :ref:`BitMap<class_BitMap>` | :ref:`texture_click_mask<class_TextureButton_property_texture_click_mask>` | |
+----------------------------------------------------+------------------------------------------------------------------------------+-----------+
| :ref:`Texture2D<class_Texture2D>` | :ref:`texture_disabled<class_TextureButton_property_texture_disabled>` | |
+----------------------------------------------------+------------------------------------------------------------------------------+-----------+
| :ref:`Texture2D<class_Texture2D>` | :ref:`texture_focused<class_TextureButton_property_texture_focused>` | |
+----------------------------------------------------+------------------------------------------------------------------------------+-----------+
| :ref:`Texture2D<class_Texture2D>` | :ref:`texture_hover<class_TextureButton_property_texture_hover>` | |
+----------------------------------------------------+------------------------------------------------------------------------------+-----------+
| :ref:`Texture2D<class_Texture2D>` | :ref:`texture_normal<class_TextureButton_property_texture_normal>` | |
+----------------------------------------------------+------------------------------------------------------------------------------+-----------+
| :ref:`Texture2D<class_Texture2D>` | :ref:`texture_pressed<class_TextureButton_property_texture_pressed>` | |
+----------------------------------------------------+------------------------------------------------------------------------------+-----------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
列舉
----
.. _enum_TextureButton_StretchMode:
.. rst-class:: classref-enumeration
enum **StretchMode**: :ref:`🔗<enum_TextureButton_StretchMode>`
.. _class_TextureButton_constant_STRETCH_SCALE:
.. rst-class:: classref-enumeration-constant
:ref:`StretchMode<enum_TextureButton_StretchMode>` **STRETCH_SCALE** = ``0``
縮放以適應節點的邊界矩形。
.. _class_TextureButton_constant_STRETCH_TILE:
.. rst-class:: classref-enumeration-constant
:ref:`StretchMode<enum_TextureButton_StretchMode>` **STRETCH_TILE** = ``1``
在節點的邊界矩形內平鋪。
.. _class_TextureButton_constant_STRETCH_KEEP:
.. rst-class:: classref-enumeration-constant
:ref:`StretchMode<enum_TextureButton_StretchMode>` **STRETCH_KEEP** = ``2``
紋理保持它的原始尺寸,並保持在邊界矩形的左上角。
.. _class_TextureButton_constant_STRETCH_KEEP_CENTERED:
.. rst-class:: classref-enumeration-constant
:ref:`StretchMode<enum_TextureButton_StretchMode>` **STRETCH_KEEP_CENTERED** = ``3``
紋理保持其原始大小,並在節點的邊界矩形中保持居中。
.. _class_TextureButton_constant_STRETCH_KEEP_ASPECT:
.. rst-class:: classref-enumeration-constant
:ref:`StretchMode<enum_TextureButton_StretchMode>` **STRETCH_KEEP_ASPECT** = ``4``
縮放紋理以適應節點的邊界矩形,但保持紋理的長寬比。
.. _class_TextureButton_constant_STRETCH_KEEP_ASPECT_CENTERED:
.. rst-class:: classref-enumeration-constant
:ref:`StretchMode<enum_TextureButton_StretchMode>` **STRETCH_KEEP_ASPECT_CENTERED** = ``5``
縮放紋理以適應節點的邊界矩形,使其居中,並保持長寬比。
.. _class_TextureButton_constant_STRETCH_KEEP_ASPECT_COVERED:
.. rst-class:: classref-enumeration-constant
:ref:`StretchMode<enum_TextureButton_StretchMode>` **STRETCH_KEEP_ASPECT_COVERED** = ``6``
縮放紋理,使較短的一邊適應邊界矩形。另一邊則裁剪到節點的界限內。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
屬性說明
--------
.. _class_TextureButton_property_flip_h:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **flip_h** = ``false`` :ref:`🔗<class_TextureButton_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_TextureButton_property_flip_v:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **flip_v** = ``false`` :ref:`🔗<class_TextureButton_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_TextureButton_property_ignore_texture_size:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **ignore_texture_size** = ``false`` :ref:`🔗<class_TextureButton_property_ignore_texture_size>`
.. rst-class:: classref-property-setget
- |void| **set_ignore_texture_size**\ (\ value\: :ref:`bool<class_bool>`\ )
- :ref:`bool<class_bool>` **get_ignore_texture_size**\ (\ )
如果為 ``true``\ ,則計算最小尺寸時不會考慮該紋理的大小,因此 **TextureButton** 能夠調整地比該紋理大小還要小。
.. rst-class:: classref-item-separator
----
.. _class_TextureButton_property_stretch_mode:
.. rst-class:: classref-property
:ref:`StretchMode<enum_TextureButton_StretchMode>` **stretch_mode** = ``2`` :ref:`🔗<class_TextureButton_property_stretch_mode>`
.. rst-class:: classref-property-setget
- |void| **set_stretch_mode**\ (\ value\: :ref:`StretchMode<enum_TextureButton_StretchMode>`\ )
- :ref:`StretchMode<enum_TextureButton_StretchMode>` **get_stretch_mode**\ (\ )
控制調整節點包圍矩形時紋理的行為。可用的選項見 :ref:`StretchMode<enum_TextureButton_StretchMode>` 常數。
.. rst-class:: classref-item-separator
----
.. _class_TextureButton_property_texture_click_mask:
.. rst-class:: classref-property
:ref:`BitMap<class_BitMap>` **texture_click_mask** :ref:`🔗<class_TextureButton_property_texture_click_mask>`
.. rst-class:: classref-property-setget
- |void| **set_click_mask**\ (\ value\: :ref:`BitMap<class_BitMap>`\ )
- :ref:`BitMap<class_BitMap>` **get_click_mask**\ (\ )
用於點擊偵測的純黑白 :ref:`BitMap<class_BitMap>` 圖像。在遮罩上,白色圖元代表按鈕的可點擊區域。可用它來建立具有彎曲形狀的按鈕。
.. rst-class:: classref-item-separator
----
.. _class_TextureButton_property_texture_disabled:
.. rst-class:: classref-property
:ref:`Texture2D<class_Texture2D>` **texture_disabled** :ref:`🔗<class_TextureButton_property_texture_disabled>`
.. rst-class:: classref-property-setget
- |void| **set_texture_disabled**\ (\ value\: :ref:`Texture2D<class_Texture2D>`\ )
- :ref:`Texture2D<class_Texture2D>` **get_texture_disabled**\ (\ )
Texture to display when the node is disabled. See :ref:`BaseButton.disabled<class_BaseButton_property_disabled>`. If not assigned, the **TextureButton** displays :ref:`texture_normal<class_TextureButton_property_texture_normal>` instead.
.. rst-class:: classref-item-separator
----
.. _class_TextureButton_property_texture_focused:
.. rst-class:: classref-property
:ref:`Texture2D<class_Texture2D>` **texture_focused** :ref:`🔗<class_TextureButton_property_texture_focused>`
.. rst-class:: classref-property-setget
- |void| **set_texture_focused**\ (\ value\: :ref:`Texture2D<class_Texture2D>`\ )
- :ref:`Texture2D<class_Texture2D>` **get_texture_focused**\ (\ )
Texture to *overlay on the base texture* when the node has mouse or keyboard focus. Because :ref:`texture_focused<class_TextureButton_property_texture_focused>` is displayed on top of the base texture, a partially transparent texture should be used to ensure the base texture remains visible. A texture that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a fully transparent texture of any size. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.
.. rst-class:: classref-item-separator
----
.. _class_TextureButton_property_texture_hover:
.. rst-class:: classref-property
:ref:`Texture2D<class_Texture2D>` **texture_hover** :ref:`🔗<class_TextureButton_property_texture_hover>`
.. rst-class:: classref-property-setget
- |void| **set_texture_hover**\ (\ value\: :ref:`Texture2D<class_Texture2D>`\ )
- :ref:`Texture2D<class_Texture2D>` **get_texture_hover**\ (\ )
Texture to display when the mouse hovers over the node. If not assigned, the **TextureButton** displays :ref:`texture_normal<class_TextureButton_property_texture_normal>` instead when hovered over.
.. rst-class:: classref-item-separator
----
.. _class_TextureButton_property_texture_normal:
.. rst-class:: classref-property
:ref:`Texture2D<class_Texture2D>` **texture_normal** :ref:`🔗<class_TextureButton_property_texture_normal>`
.. rst-class:: classref-property-setget
- |void| **set_texture_normal**\ (\ value\: :ref:`Texture2D<class_Texture2D>`\ )
- :ref:`Texture2D<class_Texture2D>` **get_texture_normal**\ (\ )
節點\ **不處於**\ 禁用、懸停、按下狀態時,預設顯示的紋理。該紋理仍會在聚焦狀態下顯示,上層繪製的是 :ref:`texture_focused<class_TextureButton_property_texture_focused>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_TextureButton_property_texture_pressed:
.. rst-class:: classref-property
:ref:`Texture2D<class_Texture2D>` **texture_pressed** :ref:`🔗<class_TextureButton_property_texture_pressed>`
.. rst-class:: classref-property-setget
- |void| **set_texture_pressed**\ (\ value\: :ref:`Texture2D<class_Texture2D>`\ )
- :ref:`Texture2D<class_Texture2D>` **get_texture_pressed**\ (\ )
Texture to display on mouse down over the node, if the node has keyboard focus and the player presses the Enter key or if the player presses the :ref:`BaseButton.shortcut<class_BaseButton_property_shortcut>` key. If not assigned, the **TextureButton** displays :ref:`texture_hover<class_TextureButton_property_texture_hover>` instead when pressed.
.. |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 (無回傳值。)`