Skip to main content

Expressions

An expression is a reusable function that takes a Sprite/Animation(or Commandable in short) and performs a predefined task, which will make your code much more cleaner. The good thing is, you can define your own expressions (and it's recommended to do so) and reuse across components. Example:

function rotateWhileMovingUp(sprite, startTime, endTime, originY, offset, angle) {
sprite.MoveY(startTime, endTime, originY, originY + offset)
sprite.Rotate(startTime, endTime, 0, angle)
}

const sprite = new Sprite("sb/bg.jpg")
// call it
rotateWhileMovingUp(sprite, 0, 1000, 240, 50, Math.PI / 2)

osbjs offers a few built-in expressions for convenient.

wiggleXY

function wiggleXY(
commandable: Commandable,
frequency: number,
amplitude: number,
startTime: number,
endTime: number,
origin?: OsbVector2 | Vector2 = new OsbVector2(320, 240)
)

Randomly shakes (wiggles) the position around an origin.

  • commandable: Sprite/Animation
  • frequency: amount of wiggles per second
  • amplitude: the maximum distance from the origin
  • startTime: start time of the expression
  • endTime: end time of the expression
  • origin: origin

wiggleX

function wiggleX(
commandable: Commandable,
frequency: number,
amplitude: number,
startTime: number,
endTime: number,
originX?: number = 320
)

Randomly shakes (wiggles) the position on the x axis around an origin.

  • commandable: Sprite/Animation
  • frequency: amount of wiggles per second
  • amplitude: the maximum distance from the origin
  • startTime: start time of the expression
  • endTime: end time of the expression
  • originX: x coordinate of the origin

wiggleY

function wiggleY(
commandable: Commandable,
frequency: number,
amplitude: number,
startTime: number,
endTime: number,
originY?: number = 240
)

Randomly shakes (wiggles) the position on the y axis around an origin.

  • commandable: Sprite/Animation
  • frequency: amount of wiggles per second
  • amplitude: the maximum distance from the origin
  • startTime: start time of the expression
  • endTime: end time of the expression
  • originY: y coordinate of the origin

wiggleRotation

function wiggleRotation(
commandable: Commandable,
frequency: number,
amplitude: number,
startTime: number,
endTime: number,
originAngle?: number = 0
)

Randomly rotates around an "origin" angle.

  • commandable: Sprite/Animation
  • frequency: amount of wiggles per second
  • amplitude: the maximum angle from the origin
  • startTime: start time of the expression
  • endTime: end time of the expression
  • originAngle: the "origin" angle

wiggleColor

function wiggleColor(
commandable: Commandable,
frequency: number,
amplitude: number,
startTime: number,
endTime: number,
gradientMin: OsbColor,
gradientMax: OsbColor
)

Randomly "wiggle" between 2 colors.

  • commandable: Sprite/Animation
  • frequency: amount of wiggles per second
  • amplitude: the maximum value the sprite's r, g, b values can be starting from the "origin".
  • startTime: start time of the expression
  • endTime: end time of the expression
  • color1, color2: "Maximum" and "minimum" colors value. The sprite's r, g, b values cannot go further than these 2's.

scaleExact

function scaleExact(
commandable: Commandable,
width: number,
height: number,
time: number,
path: string
)

Scale any image to any desired resolution without knowing the original resolution.

  • commandable: Sprite/Animation
  • width: output width
  • height: output height
  • time: time to apply the expression
  • path: full path to image file