Skip to content
Damnae edited this page Oct 20, 2021 · 14 revisions

Creating Sprites

Before sprites can be created, a layer must be retrieved with the GetLayer(name) method. Layers are used to organize sprites of an effect, making groups of sprites reorderable in the editor.

Sprites and animated sprites can be created from that layer with the following methods (origin and initialPosition are optional):

CreateSprite(path, origin, initialPosition);
CreateAnimation(path, frameCount, frameDelay, loopType, origin, initialPosition);

Example :

var layer = GetLayer("Main");
var sprite = layer.CreateSprite("bg.jpg", OsbOrigin.Centre);

Modifying Sprites

Movement

Change the position of a sprite over time. Commands similar to MoveX are available for MoveY.

Move(easing, startTime, endTime, startPosition, endPosition)
Move(easing, startTime, endTime, startX, startY, endX, endY) 
Move(startTime, endTime, startPosition, endPosition)
Move(startTime, endTime, startX, startY, endX, endY) 
Move(time, position)
Move(time, x, y)

MoveX(easing, startTime, endTime, startX, endX)
MoveX(startTime, endTime, startX, endX)
MoveX(time, x)

Scaling

Change the size of a sprite over time. 1 is the normal size, 0.5 is half the size and 2 is twice the normal size.

Scale(easing, startTime, endTime, startScale, endScale)
Scale(startTime, endTime, startScale, endScale)
Scale(time, scale)

ScaleVec(easing, startTime, endTime, startScale, endScale)
ScaleVec(easing, startTime, endTime, startX, startY, endX, endY)
ScaleVec(startTime, endTime, startScale, endScale)
ScaleVec(startTime, endTime, startX, startY, endX, endY)
ScaleVec(time, scale)
ScaleVec(time, x, y)

Rotation

Turn a sprite over time. Angles are in radians.

Rotate(easing, startTime, endTime, startRotation, endRotation)
Rotate(startTime, endTime, startRotation, endRotation)
Rotate(time, rotation)

Opacity

Change the opacity of a sprite over time. 1 is fully visible and 0 is not visible.

Fade(easing, startTime, endTime, startOpacity, endOpacity)
Fade(startTime, endTime, startOpacity, endOpacity)
Fade(time, opacity)

Color

RGB coloring: red green and blue are between 0 and 1.

Color(easing, startTime, endTime, startColor, endColor)
Color(easing, startTime, endTime, startRed, startGreen, startBlue, endRed, endGreen, endBlue)
Color(startTime, endTime, startColor, endColor)
Color(startTime, endTime, startRed, startGreen, startBlue, endRed, endGreen, endBlue)
Color(time, color)
Color(time, red, green, blue)

HSB coloring: A much more convenient color space to pick colors, see https://en.wikipedia.org/wiki/HSL_and_HSV.

  • hue an angle from 0 to 360°.
    • Red is around 0/360°.
    • Yellow is around 60°.
    • Green is around 120°.
    • Cyan is around 180°.
    • Blue is around 240°.
    • Pink is around 300°.
  • saturation from 0.0 to 1.0. Goes from grey at 0 to the fully saturated color at 1.
  • brightness from 0.0 to 1.0. Goes from black at 0 to the fully visible color at 1.
    ColorHsb(easing, startTime, endTime, startHue, startSaturation, startBrightness, endHue, endSaturation, endBrightness)
    ColorHsb(startTime, endTime, startHue, startSaturation, startBrightness, endHue, endSaturation, endBrightness)
    ColorHsb(time, hue, saturation, brightness)

Parameters

Flip a sprite horizontally/vertically or activates additive mode.

FlipH(startTime, endTime)
FlipV(startTime, endTime)
Additive(startTime, endTime)

Loops

Repeat commands loopCount times until EndGroup() is called. Command times inside the loop are relative to the startTime of the loop.

LoopCommand StartLoopGroup(startTime, loopCount)

Example:

sprite.StartLoopGroup(0, 10);
sprite.Fade(0, 500, 1, 0);
sprite.Fade(500, 1000, 0, 1);
sprite.EndGroup();

Loop (L) Command on osu!'s wiki

Triggers

Commands declared until EndGroup() is called will be active on the sprite when the triggerName event happens. Command times inside the loop are relative to the time at which the trigger is triggered.

TriggerCommand StartTriggerGroup(triggerName, startTime, endTime, group)

Example:

sprite.StartTriggerGroup("HitSoundFinish", 0, 10000);
sprite.Fade(0, 500, 1, 0);
sprite.EndGroup();

Trigger (T) Command on osu!'s wiki

Easings

Instead of using numbers for easings, an enumeration contains named values:

sprite.Fade(OsbEasing.In, 0, 500, 1, 0); // instead of 2

Visual Studio Code's IntelliSense will show a complete list of easing values when typing OsbEasing.. This list can also be found in OsbSprite.cs. They can also be previewed in osb.moe's Easing page.

Querying Sprite State

The following methods can be used to retrieve the state of a sprite at a specific time. These do not take into account unfinished loops (for which EndGroup() hasn't been called yet) or triggers.

PositionAt(time)
ScaleAt(time)
RotationAt(time)
OpacityAt(time)
ColorAt(time)
AdditiveAt(time)
FlipHAt(time)
FlipVAt(time)