1. 程式人生 > >Godot Engine 學習筆記 Texture

Godot Engine 學習筆記 Texture

Texture

Texture

以下為我對於官方文件的翻譯以及使用情況,3.0版本的文件
Texture官方文件
繼承: Resource < Reference < Object
被繼承: CurveTexture, AtlasTexture, ProxyTexture, GradientTexture, ViewportTexture, StreamTexture, ImageTexture, LargeTexture
類別:

Core

簡要說明

2D和3D紋理

成員函式

返回型別 函式
void draw ( RID canvas_item, Vector2 position, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const
void draw_rect ( RID canvas_item, Rect2 rect, bool tile, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const
void draw_rect_region ( RID canvas_item, Rect2 rect, Rect2 src_rect, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null, bool clip_uv=true ) const
Image get_data ( ) const
int get_height ( ) const
Vector2 get_size ( ) const
int get_width ( ) const
bool has_alpha ( ) const

成員變數

  • int flags - 紋理的樣式。

列舉

enum Flags

  • FLAGS_DEFAULT = 7 — 預設樣式。生成mipmaps,repeat(重複),和 filter(濾鏡)被啟用。
  • FLAG_MIPMAPS = 1 — 生成mipmaps,,它們是縮小時使用的相同紋理的較小版本,保持縱橫比。
  • FLAG_REPEAT = 2 — 重複紋理(而不是堆到邊緣)。
  • FLAG_FILTER = 4 — 放大濾鏡,使紋理平滑縮放。
  • FLAG_ANISOTROPIC_FILTER = 8 — 各向異性mipmap濾波。生成具有不同縱橫比的相同紋理的較小版本。
    當這些紋理(例如,牆壁或地面)在視口被壓扁到不同的縱橫比時,能更有效地向平面範圍展示,和常規mipmap保持縱橫比,因此在這些情況下它們不能很好地優化儲存。
  • FLAG_CONVERT_TO_LINEAR = 16 — 將紋理轉換為SRGB顏色空間。
  • FLAG_MIRRORED_REPEAT = 32 — 重複紋理與交替部分映象。
  • FLAG_VIDEO_SURFACE = 4096 — 紋理是一個視訊表面。

描述

紋理通過在視訊硬體中註冊影象來工作,然後可以在3D模型或2D精靈或GUI控制元件中使用影象。

成員函式描述

  • void draw ( RID canvas_item, Vector2 position, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const

  • void draw_rect ( RID canvas_item, Rect2 rect, bool tile, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null ) const

  • void draw_rect_region ( RID canvas_item, Rect2 rect, Rect2 src_rect, Color modulate=Color( 1, 1, 1, 1 ), bool transpose=false, Texture normal_map=null, bool clip_uv=true ) const

  • Image get_data ( ) const

  • int get_height ( ) const

返回紋理高度。

  • Vector2 get_size ( ) const

返回紋理大小。

  • int get_width ( ) const

返回紋理寬度。

  • bool has_alpha ( ) const

使用

關於get_height()、get_size()、get_width()的使用。
建立場景。

  • Node
    • Sprite
    • Label
    • Button

為根節點新增指令碼,連線Button的pressed()訊號。
在這裡插入圖片描述
直接將圖片衝=從資源欄拖進Sprite節點的Texture屬性。
在這裡插入圖片描述
單擊屬性欄中顯示的圖片,檢視texture的詳細資訊。
在這裡插入圖片描述
可以看出圖片拖進去後,為節點的Texture屬性新建一個StreamTexture類的物件,這個StreamTexture類是Texture的子類,那也就繼承了父類Texture的函式。
設定下控制元件位置大小。
在這裡插入圖片描述
為指令碼新增程式碼。
在這裡插入圖片描述
執行下。
在這裡插入圖片描述
檢視下圖片的屬性。
在這裡插入圖片描述