TileSetAtlasSource

Успадковує: TileSetSource < Resource < RefCounted < Object

Експолює текстуру 2D як набір плитки для ресурсу TileSet.

Опис

Атлас - сітка з плитки, викладена на фактурі. Кожна плитка в сітці повинна бути виставлена за допомогою create_tile(). Потім за допомогою координат в сітці зараховується плитка.

Кожна плитка може також мати розмір в сітчастих координатах, що робить її більш-менш осередками в атласі.

Альтернативна версія плитки може бути створена за допомогою create_alternative_tile(), які потім індексуються за допомогою альтернативного ID. Основна плитка (в одній в сітці) має доступ до альтернативного ID до 0.

Кожна черепиця чергується має набір властивостей, які визначаються шарами джерела TileSet. Ці властивості зберігаються в об'єкті TileData, який може бути доступним і модифікованим за допомогою get_tile_data().

Як властивості TileData зберігаються безпосередньо в ресурсі TileSetAtlasSource, їх властивості можуть бути використані TileSetAtlasSource.set("<coords_x>:<coords_y>/<alternative_id>/<tile_data_property>").

Властивості

Vector2i

margins

Vector2i(0, 0)

Vector2i

separation

Vector2i(0, 0)

Texture2D

texture

Vector2i

texture_region_size

Vector2i(16, 16)

bool

use_texture_padding

true

Методи

void

clear_tiles_outside_texture()

int

create_alternative_tile(atlas_coords: Vector2i, alternative_id_override: int = -1)

void

create_tile(atlas_coords: Vector2i, size: Vector2i = Vector2i(1, 1))

Vector2i

get_atlas_grid_size() const

int

get_next_alternative_tile_id(atlas_coords: Vector2i) const

Texture2D

get_runtime_texture() const

Rect2i

get_runtime_tile_texture_region(atlas_coords: Vector2i, frame: int) const

int

get_tile_animation_columns(atlas_coords: Vector2i) const

float

get_tile_animation_frame_duration(atlas_coords: Vector2i, frame_index: int) const

int

get_tile_animation_frames_count(atlas_coords: Vector2i) const

TileAnimationMode

get_tile_animation_mode(atlas_coords: Vector2i) const

Vector2i

get_tile_animation_separation(atlas_coords: Vector2i) const

float

get_tile_animation_speed(atlas_coords: Vector2i) const

float

get_tile_animation_total_duration(atlas_coords: Vector2i) const

Vector2i

get_tile_at_coords(atlas_coords: Vector2i) const

TileData

get_tile_data(atlas_coords: Vector2i, alternative_tile: int) const

Vector2i

get_tile_size_in_atlas(atlas_coords: Vector2i) const

Rect2i

get_tile_texture_region(atlas_coords: Vector2i, frame: int = 0) const

PackedVector2Array

get_tiles_to_be_removed_on_change(texture: Texture2D, margins: Vector2i, separation: Vector2i, texture_region_size: Vector2i)

bool

has_room_for_tile(atlas_coords: Vector2i, size: Vector2i, animation_columns: int, animation_separation: Vector2i, frames_count: int, ignored_tile: Vector2i = Vector2i(-1, -1)) const

bool

has_tiles_outside_texture() const

void

move_tile_in_atlas(atlas_coords: Vector2i, new_atlas_coords: Vector2i = Vector2i(-1, -1), new_size: Vector2i = Vector2i(-1, -1))

void

remove_alternative_tile(atlas_coords: Vector2i, alternative_tile: int)

void

remove_tile(atlas_coords: Vector2i)

void

set_alternative_tile_id(atlas_coords: Vector2i, alternative_tile: int, new_id: int)

void

set_tile_animation_columns(atlas_coords: Vector2i, frame_columns: int)

void

set_tile_animation_frame_duration(atlas_coords: Vector2i, frame_index: int, duration: float)

void

set_tile_animation_frames_count(atlas_coords: Vector2i, frames_count: int)

void

set_tile_animation_mode(atlas_coords: Vector2i, mode: TileAnimationMode)

void

set_tile_animation_separation(atlas_coords: Vector2i, separation: Vector2i)

void

set_tile_animation_speed(atlas_coords: Vector2i, speed: float)


Переліки

enum TileAnimationMode: 🔗

TileAnimationMode TILE_ANIMATION_MODE_DEFAULT = 0

В той же час, дивлячись на ідентичність.

TileAnimationMode TILE_ANIMATION_MODE_RANDOM_START_TIMES = 1

У випадковому режимі, див. різноманітні.

TileAnimationMode TILE_ANIMATION_MODE_MAX = 2

Представляємо розмір TileAnimationMode enum.


Константи

TRANSFORM_FLIP_H = 4096 🔗

Представляє прапорець горизонтального відображення комірки. Слід використовувати безпосередньо з TileMapLayer для відображення розміщених плиток шляхом зміни їхніх альтернативних ідентифікаторів.

var alternate_id = $TileMapLayer.get_cell_alternative_tile(Vector2i(2, 2))
if not alternate_id & TileSetAtlasSource.TRANSFORM_FLIP_H:
# Якщо плитка ще не відображена, відобразити її.
 $TileMapLayer.set_cell(Vector2i(2, 2), source_id, atlas_coords, alternate_id | TileSetAtlasSource.TRANSFORM_FLIP_H)

Примітка: Ці перетворення можна комбінувати для виконання еквівалентів поворотів на 0, 90, 180 та 270 градусів, як показано нижче:

enum TileTransform {
ROTATE_0 = 0,
ROTATE_90 = TileSetAtlasSource.TRANSFORM_TRANSPOSE | TileSetAtlasSource.TRANSFORM_FLIP_H,
ROTATE_180 = TileSetAtlasSource.TRANSFORM_FLIP_H | TileSetAtlasSource.TRANSFORM_FLIP_V,
ROTATE_270 = TileSetAtlasSource.TRANSFORM_TRANSPOSE | TileSetAtlasSource.TRANSFORM_FLIP_V,
}

TRANSFORM_FLIP_V = 8192 🔗

Представляє вертикальний прапор комірки. Див. TRANSFORM_FLIP_H для використання.

TRANSFORM_TRANSPOSE = 16384 🔗

Представляє транспонований прапор комірки. Див. TRANSFORM_FLIP_H для використання.


Описи властивостей

Vector2i margins = Vector2i(0, 0) 🔗

Маргіни, у пікселях, щоб згасити походження сітки в текстурі.


Vector2i separation = Vector2i(0, 0) 🔗

Сепарація, в пікселях, між кожною фактурою плитки області сітки.


Texture2D texture 🔗

Текстура атласа.


Vector2i texture_region_size = Vector2i(16, 16) 🔗

  • void set_texture_region_size(value: Vector2i)

  • Vector2i get_texture_region_size()

Базовий розмір тайла в текстурі (у пікселях). Цей розмір має бути більшим або дорівнювати значенню tile_size TileSet.


bool use_texture_padding = true 🔗

  • void set_use_texture_padding(value: bool)

  • bool get_use_texture_padding()

Якщо true, генерує внутрішню фактуру з додатковою кількістюпікселів навколо кожної плитки. Текстурний наповнювач дозволяє уникнути спільного артефакту, де між плитками з'являються лінії.

Відключення цієї налаштування може призвести до невеликого поліпшення продуктивності, оскільки створення внутрішньої текстури вимагає як пам'яті, так і для обробки часу, коли модифікований ресурс TileSetAtlasSource.


Описи методів

void clear_tiles_outside_texture() 🔗

Видаліть всі плитки, які не підходять до наявної фактури. Цей метод ітерує по всій плитці джерела, тому рекомендується використовувати has_tiles_outside_texture() перед рукою.


int create_alternative_tile(atlas_coords: Vector2i, alternative_id_override: int = -1) 🔗

Створює альтернативну плитку для плитки в координатах atlas_coords. Якщо альтернатива_id_override є -1, дати йому автоматично сформований унікальний ідентифікатор або призначає його заданий ідентифікатор.

Повертає новий ідентифікатор альтернативи, або -1, якщо альтернатива не може бути створена з наданою альтернатива_id_override.


void create_tile(atlas_coords: Vector2i, size: Vector2i = Vector2i(1, 1)) 🔗

Створює нову плитку в координатах atlas_coords з наданою size.


Vector2i get_atlas_grid_size() const 🔗

Повертає розмір сітки атласу, який залежить від того, скільки плиток може поміститися в текстуру. Таким чином, він залежить від розміру texture, margins атласу та texture_region_size плиток.


int get_next_alternative_tile_id(atlas_coords: Vector2i) const 🔗

Повертає альтернативний ідентифікатор, який поверне наступний виклик методу create_alternative_tile().


Texture2D get_runtime_texture() const 🔗

Якщо use_texture_padding має значення false, повертає texture. В іншому випадку повертає внутрішню ImageTexture, створену з урахуванням padding.


Rect2i get_runtime_tile_texture_region(atlas_coords: Vector2i, frame: int) const 🔗

Повертає область плитки за координатами atlas_coords для заданого frame всередині текстури, повернутої методом get_runtime_texture().

Примітка: Якщо use_texture_padding має значення false, повертає те саме, що й get_tile_texture_region().


int get_tile_animation_columns(atlas_coords: Vector2i) const 🔗

Повертає, скільки стовпців плитка на atlas_coords має в своєму анімаційному макеті.


float get_tile_animation_frame_duration(atlas_coords: Vector2i, frame_index: int) const 🔗

Повертає тривалість анімації кадру frame_index для плитки в координатах atlas_coords.


int get_tile_animation_frames_count(atlas_coords: Vector2i) const 🔗

Повертає, як багато анімаційних кадрів має плитку на координатах atlas_coords.


TileAnimationMode get_tile_animation_mode(atlas_coords: Vector2i) const 🔗

Повертає кахельний анімаційний режим плитки на atlas_coords. Дивись також set_tile_animation_mode().


Vector2i get_tile_animation_separation(atlas_coords: Vector2i) const 🔗

Повертає поділ (як у сітчастій сітці) між координаторами atlas_coords.


float get_tile_animation_speed(atlas_coords: Vector2i) const 🔗

Повернення швидкості анімації на координатах atlas_coords.


float get_tile_animation_total_duration(atlas_coords: Vector2i) const 🔗

Повертає сума суми каркасних тривалостей плитки на координатах atlas_coords. Ця вартість повинна бути розділена на швидкість анімації, щоб отримати фактичну тривалість петлі анімації.


Vector2i get_tile_at_coords(atlas_coords: Vector2i) const 🔗

Якщо є плитка, що охоплює координати atlas_coords, повертає топ-ліві координати плитки (в його координати ID). Vector2i(-1, -1) інакше.


TileData get_tile_data(atlas_coords: Vector2i, alternative_tile: int) const 🔗

Повернення об'єкта TileData для координат та альтернативного ID.


Vector2i get_tile_size_in_atlas(atlas_coords: Vector2i) const 🔗

Повертає розмір плитки (в системі сітчастих координат) у координатах atlas_coords.


Rect2i get_tile_texture_region(atlas_coords: Vector2i, frame: int = 0) const 🔗

Повертає фактуру плитки в фактурі атласу. Для анімаційної плитки, аргумент frame може бути надана для різних кадрів анімації.


PackedVector2Array get_tiles_to_be_removed_on_change(texture: Texture2D, margins: Vector2i, separation: Vector2i, texture_region_size: Vector2i) 🔗

Повертає масив координат плиток, ідентифікатор яких буде автоматично видалено під час зміни однієї або кількох із цих властивостей: texture, margins, separation або texture_region_size. Це можна використовувати для скасування змін, які могли б призвести до втрати даних плиток.


bool has_room_for_tile(atlas_coords: Vector2i, size: Vector2i, animation_columns: int, animation_separation: Vector2i, frames_count: int, ignored_tile: Vector2i = Vector2i(-1, -1)) const 🔗

Повертає, чи є достатня кімната в апласі, щоб створити/модифікувати плитку з заданими властивостями. Якщо ignored_tile передбачено, дія як дана плитка не була присутніми в атласі. Це може бути використаний при бажанні змінити властивості плитки.


bool has_tiles_outside_texture() const 🔗

Перевіряє, якщо джерело має будь-яку плитку, яка не вписується в область текстури.


void move_tile_in_atlas(atlas_coords: Vector2i, new_atlas_coords: Vector2i = Vector2i(-1, -1), new_size: Vector2i = Vector2i(-1, -1)) 🔗

Перемістіть плитку та її альтернативи за координатами atlas_coords у координати new_atlas_coords з розміром new_size. Ця функція не виконає роботу, якщо плитка вже присутня у заданій області.

Якщо new_atlas_coords дорівнює Vector2i(-1, -1), зберігає координати плитки. Якщо new_size дорівнює Vector2i(-1, -1), зберігає розмір плитки.

Щоб уникнути помилки, спочатку перевірте, чи можливе переміщення, використовуючи has_room_for_tile().


void remove_alternative_tile(atlas_coords: Vector2i, alternative_tile: int) 🔗

Видалити альтернативу плитки з ідентифікатором альтернативи alternative_tile.

Виклик цієї функції з alternative_tile, що дорівнює 0, завершиться невдачею, оскільки базову альтернативу плитки неможливо видалити.


void remove_tile(atlas_coords: Vector2i) 🔗

Видаліть плитку та її альтернативу координаціям atlas_coords.


void set_alternative_tile_id(atlas_coords: Vector2i, alternative_tile: int, new_id: int) 🔗

Змініть альтернативний ідентифікатор плитки з alternative_tile на new_id.

Виклик цієї функції зі значенням new_id, що дорівнює 0, завершиться невдачею, оскільки базову альтернативу плитки неможливо перемістити.


void set_tile_animation_columns(atlas_coords: Vector2i, frame_columns: int) 🔗

Встановлює кількість стовпців у макеті анімації плитки за координатами atlas_coords. Якщо встановити значення 0, то різні кадри анімації розташовуються в атласі як одна горизонтальна лінія.


void set_tile_animation_frame_duration(atlas_coords: Vector2i, frame_index: int, duration: float) 🔗

Набори анімаційного каркасу duration рами frame_index для плитки в координатах atlas_coords.


void set_tile_animation_frames_count(atlas_coords: Vector2i, frames_count: int) 🔗

Встановлює, як багато анімаційних кадрів плитка в координатах atlas_coords.


void set_tile_animation_mode(atlas_coords: Vector2i, mode: TileAnimationMode) 🔗

Встановлює режим кахельної анімації плитки в atlas_coords до mode. Дивитися також get_tile_animation_mode().


void set_tile_animation_separation(atlas_coords: Vector2i, separation: Vector2i) 🔗

Встановлює запас (у сітку плитку) між кожною плиткою в анімаційному макеті плитки в координатах atlas_coords.


void set_tile_animation_speed(atlas_coords: Vector2i, speed: float) 🔗

Налаштовує швидкість анімації плитки в координатах atlas_coords.