PackedVector4Array

Un array empaquetado de Vector4s.

Descripción

Un array diseñado específicamente para contener Vector4s. Empaqueta los datos de forma compacta, por lo que ahorra memoria para arrays de gran tamaño.

Diferencias entre arrays empaquetados, tipados y no tipados Los arrays empaquetados son generalmente más rápidos de iterar y modificar en comparación con un array tipado del mismo tipo (por ejemplo, PackedVector4Array frente a Array[Vector4]). Además, los arrays empaquetados consumen menos memoria. Como desventaja, los arrays empaquetados son menos flexibles, ya que no ofrecen tantos métodos de conveniencia como Array.map(). Los arrays tipados son a su vez más rápidos de iterar y modificar que los arrays no tipados.

Nota: Los arrays empaquetados siempre se pasan por referencia. Para obtener una copia de un array que se pueda modificar independientemente del original, utiliza duplicate(). Este no es el caso de las propiedades y métodos incorporados. En estos casos, el array empaquetado devuelto es una copia, y su modificación no afectará al valor original. Para actualizar una propiedad incorporada de este tipo, modifica el array devuelto y luego asígnalo de nuevo a la propiedad.

Nota

Hay diferencias notables cuando usa esta API con C#. Véase Diferencias de la API de C# con GDScript para más información.

Constructores

PackedVector4Array

PackedVector4Array()

PackedVector4Array

PackedVector4Array(from: PackedVector4Array)

PackedVector4Array

PackedVector4Array(from: Array)

Métodos

bool

append(value: Vector4)

void

append_array(array: PackedVector4Array)

int

bsearch(value: Vector4, before: bool = true)

void

clear()

int

count(value: Vector4) const

PackedVector4Array

duplicate()

bool

erase(value: Vector4)

void

fill(value: Vector4)

int

find(value: Vector4, from: int = 0) const

Vector4

get(index: int) const

bool

has(value: Vector4) const

int

insert(at_index: int, value: Vector4)

bool

is_empty() const

bool

push_back(value: Vector4)

void

remove_at(index: int)

int

resize(new_size: int)

void

reverse()

int

rfind(value: Vector4, from: int = -1) const

void

set(index: int, value: Vector4)

int

size() const

PackedVector4Array

slice(begin: int, end: int = 2147483647) const

void

sort()

PackedByteArray

to_byte_array() const

Operadores

bool

operator !=(right: PackedVector4Array)

PackedVector4Array

operator +(right: PackedVector4Array)

bool

operator ==(right: PackedVector4Array)

Vector4

operator [](index: int)


Descripciones de Constructores

PackedVector4Array PackedVector4Array() 🔗

Construye un PackedVector4Array vacío.


PackedVector4Array PackedVector4Array(from: PackedVector4Array)

Construye un PackedVector4Array como una copia del PackedVector4Array dado.


PackedVector4Array PackedVector4Array(from: Array)

Construye un nuevo PackedVector4Array. Opcionalmente, puedes pasar un Array genérico que será convertido.

Nota: Al inicializar un PackedVector4Array con elementos, debe ser inicializado con un Array de valores Vector4:

var array = PackedVector4Array([Vector4(12, 34, 56, 78), Vector4(90, 12, 34, 56)])

Descripciones de Métodos

bool append(value: Vector4) 🔗

Concatena un elemento al final del array (alias de push_back()).


void append_array(array: PackedVector4Array) 🔗

Añade un PackedVector4Array al final de este array.


int bsearch(value: Vector4, before: bool = true) 🔗

Finds the index of an existing value (or the insertion index that maintains sorting order, if the value is not yet present in the array) using binary search. Optionally, a before specifier can be passed. If false, the returned index comes after all existing entries of the value in the array.

Note: Calling bsearch() on an unsorted array results in unexpected behavior.

Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.


void clear() 🔗

Limpia el array. Esto es equivalente a usar resize() con un tamaño de 0.


int count(value: Vector4) const 🔗

Returns the number of times an element is in the array.

Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.


PackedVector4Array duplicate() 🔗

Creates a copy of the array, and returns it.


bool erase(value: Vector4) 🔗

Removes the first occurrence of a value from the array and returns true. If the value does not exist in the array, nothing happens and false is returned. To remove an element by index, use remove_at() instead.

Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.


void fill(value: Vector4) 🔗

Asigna el valor dado a todos los elementos del array. Esto normalmente se puede usar junto con resize() para crear un array con un tamaño dado y elementos inicializados.


int find(value: Vector4, from: int = 0) const 🔗

Searches the array for a value and returns its index or -1 if not found. Optionally, the initial search index can be passed.

Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.


Vector4 get(index: int) const 🔗

Returns the Vector4 at the given index in the array. If index out-of-bounds or negative, this method fails and returns Vector4(0, 0, 0, 0).

This method is similar (but not identical) to the [] operator. Most notably, when this method fails, it doesn't pause project execution if run from the editor.


bool has(value: Vector4) const 🔗

Returns true if the array contains value.

Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.


int insert(at_index: int, value: Vector4) 🔗

Inserta un nuevo elemento en una posición determinada del array. La posición debe ser válida, o al final del array (idx == size()).


bool is_empty() const 🔗

Devuelve true si el array es vacio.


bool push_back(value: Vector4) 🔗

Inserta un Vector4 al final.


void remove_at(index: int) 🔗

Elimina un elemento del array por indice.


int resize(new_size: int) 🔗

Sets the size of the array. If the array is grown, reserves elements at the end of the array. If the array is shrunk, truncates the array to the new size. Calling resize() once and assigning the new values is faster than adding new elements one by one.

Returns @GlobalScope.OK on success, or one of the following Error constants if this method fails: @GlobalScope.ERR_INVALID_PARAMETER if the size is negative, or @GlobalScope.ERR_OUT_OF_MEMORY if allocations fail. Use size() to find the actual size of the array after resize.


void reverse() 🔗

Invierte el orden de los elementos en el array.


int rfind(value: Vector4, from: int = -1) const 🔗

Searches the array in reverse order. Optionally, a start search index can be passed. If negative, the start index is considered relative to the end of the array.

Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.


void set(index: int, value: Vector4) 🔗

Cambia el Vector4 en el índice dado.


int size() const 🔗

Devuelve el numer de elementos en el array.


PackedVector4Array slice(begin: int, end: int = 2147483647) const 🔗

Returns the slice of the PackedVector4Array, from begin (inclusive) to end (exclusive), as a new PackedVector4Array.

The absolute value of begin and end will be clamped to the array size, so the default value for end makes it slice to the size of the array by default (i.e. arr.slice(1) is a shorthand for arr.slice(1, arr.size())).

If either begin or end are negative, they will be relative to the end of the array (i.e. arr.slice(0, -2) is a shorthand for arr.slice(0, arr.size() - 2)).


void sort() 🔗

Sorts the elements of the array in ascending order.

Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.


PackedByteArray to_byte_array() const 🔗

Returns a PackedByteArray with each vector encoded as bytes.


Descripciones de Operadores

bool operator !=(right: PackedVector4Array) 🔗

Returns true if contents of the arrays differ.


PackedVector4Array operator +(right: PackedVector4Array) 🔗

Returns a new PackedVector4Array with contents of right added at the end of this array. For better performance, consider using append_array() instead.


bool operator ==(right: PackedVector4Array) 🔗

Returns true if contents of both arrays are the same, i.e. they have all equal Vector4s at the corresponding indices.


Vector4 operator [](index: int) 🔗

Returns the Vector4 at index index. Negative indices can be used to access the elements starting from the end. Using index out of array's bounds will result in an error.