sonolus.script.sprite¶
RenderMode
¶
Bases: StrEnum
Render mode for sprites.
DEFAULT = 'default'
class-attribute
instance-attribute
¶
Use the user's preferred render mode.
LIGHTWEIGHT = 'lightweight'
class-attribute
instance-attribute
¶
Use the lightweight render mode with projective interpolation of textures.
STANDARD = 'standard'
class-attribute
instance-attribute
¶
Use the standard render mode with bilinear interpolation of textures.
Sprite
¶
Bases: Record
Skin sprite.
Usage
Sprite(id: int)
is_available: bool
property
¶
Check if the sprite is available.
draw(quad: QuadLike, z: float = 0.0, a: float = 1.0)
¶
Draw the sprite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quad
|
QuadLike
|
The quad to draw the sprite on. |
required |
z
|
float
|
The z-index of the sprite. |
0.0
|
a
|
float
|
The alpha of the sprite. |
1.0
|
draw_curved_b(quad: QuadLike, cp: Vec2, n: float, z: float = 0.0, a: float = 1.0)
¶
Draw the sprite with a curved bottom with a quadratic Bézier curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quad
|
QuadLike
|
The quad to draw the sprite on. |
required |
cp
|
Vec2
|
The control point of the curve. |
required |
n
|
float
|
The number of segments to approximate the curve (higher is smoother but more expensive). |
required |
z
|
float
|
The z-index of the sprite. |
0.0
|
a
|
float
|
The alpha of the sprite. |
1.0
|
draw_curved_bt(quad: QuadLike, cp1: Vec2, cp2: Vec2, n: float, z: float = 0.0, a: float = 1.0)
¶
Draw the sprite with a curved bottom and top with a cubic Bézier curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quad
|
QuadLike
|
The quad to draw the sprite on. |
required |
cp1
|
Vec2
|
The control point of the bottom curve. |
required |
cp2
|
Vec2
|
The control point of the top curve. |
required |
n
|
float
|
The number of segments to approximate the curve (higher is smoother but more expensive). |
required |
z
|
float
|
The z-index of the sprite. |
0.0
|
a
|
float
|
The alpha of the sprite. |
1.0
|
draw_curved_l(quad: QuadLike, cp: Vec2, n: float, z: float = 0.0, a: float = 1.0)
¶
Draw the sprite with a curved left side with a quadratic Bézier curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quad
|
QuadLike
|
The quad to draw the sprite on. |
required |
cp
|
Vec2
|
The control point of the curve. |
required |
n
|
float
|
The number of segments to approximate the curve (higher is smoother but more expensive). |
required |
z
|
float
|
The z-index of the sprite. |
0.0
|
a
|
float
|
The alpha of the sprite. |
1.0
|
draw_curved_lr(quad: QuadLike, cp1: Vec2, cp2: Vec2, n: float, z: float = 0.0, a: float = 1.0)
¶
Draw the sprite with a curved left and right side with a cubic Bézier curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quad
|
QuadLike
|
The quad to draw the sprite on. |
required |
cp1
|
Vec2
|
The control point of the left curve. |
required |
cp2
|
Vec2
|
The control point of the right curve. |
required |
n
|
float
|
The number of segments to approximate the curve (higher is smoother but more expensive). |
required |
z
|
float
|
The z-index of the sprite. |
0.0
|
a
|
float
|
The alpha of the sprite. |
1.0
|
draw_curved_r(quad: QuadLike, cp: Vec2, n: float, z: float = 0.0, a: float = 1.0)
¶
Draw the sprite with a curved right side with a quadratic Bézier curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quad
|
QuadLike
|
The quad to draw the sprite on. |
required |
cp
|
Vec2
|
The control point of the curve. |
required |
n
|
float
|
The number of segments to approximate the curve (higher is smoother but more expensive). |
required |
z
|
float
|
The z-index of the sprite. |
0.0
|
a
|
float
|
The alpha of the sprite. |
1.0
|
draw_curved_t(quad: QuadLike, cp: Vec2, n: float, z: float = 0.0, a: float = 1.0)
¶
Draw the sprite with a curved top with a quadratic Bézier curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quad
|
QuadLike
|
The quad to draw the sprite on. |
required |
cp
|
Vec2
|
The control point of the curve. |
required |
n
|
float
|
The number of segments to approximate the curve (higher is smoother but more expensive). |
required |
z
|
float
|
The z-index of the sprite. |
0.0
|
a
|
float
|
The alpha of the sprite. |
1.0
|
SpriteGroup
¶
StandardSprite
¶
Standard skin sprites.
skin(cls: type[T]) -> T | Skin
¶
Decorator to define a skin.
Usage
@skin
class Skin:
render_mode: RenderMode = RenderMode.LIGHTWEIGHT
note: StandardSprite.NOTE_HEAD_RED
other: Sprite = sprite("other")
group_1: SpriteGroup = sprite_group(["one", "two", "three"])
group_2: SpriteGroup = sprite_group(f"name_{i}" for i in range(10))
sprite(name: str) -> Any
¶
Define a sprite with the given name.
sprite_group(names: Iterable[str]) -> Any
¶
Define a sprite group with the given names.