Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
ImageTextureLayered
繼承: TextureLayered < Texture < Resource < RefCounted < Object
被繼承: Cubemap, CubemapArray, Texture2DArray
紋理型別的基底類別,包含多個 ImageTexture 的資料。各個影像具有相同的大小和格式。
說明
Texture2DArray、Cubemap 和 CubemapArray 的基底類別。不能直接使用,但包含了存取衍生資源型別所需的所有函式。另請參閱 Texture3D。
方法
create_from_images(images: Array[Image]) |
|
void |
update_layer(image: Image, layer: int) |
方法說明
Error create_from_images(images: Array[Image]) 🔗
根據 Image 陣列建立 ImageTextureLayered,所需的資料格式見 Image.create()。寬度、高度、影像格式、Mipmap 等設定由第一個影像決定,其他影像必須保持一致。
每個 Image 都代表一層 layer。
# 為陣列中的影像填充不同的顏色。
var images = []
const LAYERS = 6
for i in LAYERS:
var image = Image.create_empty(128, 128, false, Image.FORMAT_RGB8)
if i % 3 == 0:
image.fill(Color.RED)
elif i % 3 == 1:
image.fill(Color.GREEN)
else:
image.fill(Color.BLUE)
images.push_back(image)
# 建立並儲存 2D 紋理陣列。影像陣列中必須至少有 1 個影像。
var texture_2d_array = Texture2DArray.new()
texture_2d_array.create_from_images(images)
ResourceSaver.save(texture_2d_array, "res://texture_2d_array.res", ResourceSaver.FLAG_COMPRESS)
# 建立並儲存立方體貼圖。影像陣列中影像的數量必須為 6。
# 立方體貼圖影像的順序為:X+、X-、Y+、Y-、Z+、Z-
# (使用 Godot 的座標系,因此 Y+ 是“上”、Z- 是“前”)。
var cubemap = Cubemap.new()
cubemap.create_from_images(images)
ResourceSaver.save(cubemap, "res://cubemap.res", ResourceSaver.FLAG_COMPRESS)
# 建立並儲存立方體貼圖陣列。影像陣列中影像的數量必須為 6 的倍數。
# 每個立方體貼圖影像的順序為:X+、X-、Y+、Y-、Z+、Z-
# (使用 Godot 的座標系,因此 Y+ 是“上”、Z- 是“前”)。
var cubemap_array = CubemapArray.new()
cubemap_array.create_from_images(images)
ResourceSaver.save(cubemap_array, "res://cubemap_array.res", ResourceSaver.FLAG_COMPRESS)
void update_layer(image: Image, layer: int) 🔗
用這個新影像替換給定 layer 的現有 Image 資料。
給定的 Image 必須與其餘參照的影像具有相同的寬度、高度、影像格式和多級漸遠紋理標誌。
如果影像格式不受支援,它將被解壓縮並轉換為一個相似且受支援的 Format。
更新是即時的:它與繪製同步。