Skip to main content

Sprite.Create(Texture2D texture, Rect rect, Vector2 pivot, number pixelsPerUnit)

Create a new Sprite object.

Parameters:

NameTypeDescription
textureTexture2DThe Texture to obtain the Sprite graphic from.
rectRectThe rectangular section of the Texture to use for the Sprite.
pivotVector2The Sprite's pivot point relative to its graphic rectangle.
pixelsPerUnitnumberThe number of pixels in the Sprite that correspond to one unit in world space.

Returns:

typeDescription
Spritenew Sprite object.

Usage

---@type Texture2D
local texture;

---@type Rect
local rect;

---@type Vector2
local pivot;

---@type number
local pixelsPerUnit;


local val0 = Sprite:Create(texture, rect, pivot, pixelsPerUnit)

Type/index.html) |The type of mesh that is generated for the Sprite. | |border | Vector4 |The border sizes of the Sprite (X=left, Y=bottom, Z=right, W=top). |

Returns:

typeDescription
Spritenew Sprite object.

Usage

---@type Texture2D
local texture;

---@type Rect
local rect;

---@type Vector2
local pivot;

---@type number
local pixelsPerUnit;

---@type number
local extrude;

---@type SpriteMeshType
local meshType;

---@type Vector4
local border;


local val0 = Sprite:Create(texture, rect, pivot, pixelsPerUnit, extrude, meshType, border)

PerUnit;

---@type number local extrude;

---@type SpriteMeshType local meshType;

---@type Vector4 local border;

---@type boolean local generateFallbackPhysicsShape;

local val0 = Sprite:Create(texture, rect, pivot, pixelsPerUnit, extrude, meshType, border, generateFallbackPhysicsShape)