Sprite

Reference for the Sprite prefab, a simple 2D quad that automatically sizes to its texture.

Sprite

Sprite(texture=None, ppu:int=None, **kwargs)

Located in ursina/prefabs/sprite.py

Overview

Sprite is a subclass of Entity with a quad model and automatic scaling so that one pixel in the texture equals one world unit (pixels‑per‑unit).

Constructor Arguments

ArgumentTypeDefaultDescription
texturestrNoneName or path of the texture to apply.
ppuintNonePixels‑per‑unit. Overrides Sprite.ppu.
**kwargsanyAny other Entity attributes (position, color, parent, etc.).

Class Fields

NameTypeDefaultDescription
Sprite.ppuint100Default pixels‑per‑unit for all sprites.
.modelstr'quad'The mesh used (always a quad).
.texturestrtextureThe texture assigned.
.ppuintppu || Sprite.ppuEffective pixels‑per‑unit.

Methods

update_scale()

Recompute the entity’s scale based on its texture size and the current ppu. Called once at init. Call again if you change .texture or .ppu.

Example Usage

from ursina import *

app = Ursina()
camera.orthographic = True
camera.fov = 1

# change default pixels‑per‑unit
Sprite.ppu = 16

# disable texture filtering for pixel‑perfect look
Texture.default_filtering = False

# create a brick sprite at origin
s = Sprite('brick', filtering=False)

app.run()