Skip to content

Colour effects

Updated

Colour effects change the tones of the whole image: an old-photo Sepia, a black-and-white Grayscale, a shift in Hue/Saturation, and a Vignette that darkens the edges. Each is one component on a camera.

ComponentTypeWhat it does
Hue Saturation Effectcomp-hue-saturation-effectShifts the colours around the colour wheel and makes them duller or more vivid.
Sepia Effectcomp-sepia-effectTints the image brown, like an old photograph.
Grayscale Effectcomp-grayscale-effectRenders the image in black and white.
Vignette Effectcomp-vignette-effectDarkens the edges of the image.

HueSaturationEffectComponent turns colours around the colour wheel and changes how vivid they are.

Prop Type Default Description
hue number 0 Turn of every colour around the wheel, in degrees, -180 to 180.
saturation number 0 Colourfulness: -1 grey, 0 unchanged, 1 vivid.

SepiaEffectComponent tints the image brown, like an old photograph.

Prop Type Default Description
intensity number 1 How strongly the brown tone replaces the colours, 0 to 1.

GrayscaleEffectComponent renders the image in black and white.

Prop Type Default Description
intensity number 1 How far the colours fade to grey, 0 to 1.

VignetteEffectComponent darkens the edges of the image.

Prop Type Default Description
darkness number 0.5 How dark the edges get, 0 to 1.
offset number 0.5 How far from the centre the darkening starts, 0 to 1.

1. Flash the screen when the player is hurt

Section titled “1. Flash the screen when the player is hurt”

Damage feedback: the vignette darkens sharply and recovers, and the image glitches for a moment. Another script emits player/hurt with the damage amount. The Glitch effect is saved on the camera with active set to false.

HurtFeedback.jx
#pragma lifecycle(startup)
let vignette;
let glitch;
let pulse = null;
let quiet = null;
function startup() {
const eye = findEntity('Main Camera');
vignette = eye.getComponent(VignetteEffectComponent);
glitch = eye.getComponent(GlitchEffectComponent);
glitch.setProps({ active: false });
on('player/hurt', (data) => {
const amount = Math.min(1, (data?.damage ?? 10) / 50);
const peak = 0.5 + 0.45 * amount;
if (pulse) pulse.stop();
pulse = Tween.value(peak, 0.5, (value) => vignette.setProps({ darkness: value }), {
duration: 0.6, ease: Ease.OutQuad,
});
glitch.setProps({ active: true, strength: [0.2, 0.4 + 0.6 * amount] });
if (quiet) quiet();
quiet = delay(() => glitch.setProps({ active: false }), 400);
});
}
  • Bigger hits darken the edges more: amount maps the damage to 0..1, and peak sits between the resting 0.5 and 0.95.
  • The vignette jumps to peak and eases back to 0.5. A new hit stops the previous pulse first, so two tweens never fight over darkness.
  • Glitch is switched with its active prop instead of setEnabled. The effect stays in the chain, so turning it on costs no rebuild.
  • delay(..., 400) quiets the glitch after 400 ms. The previous delay is cancelled when a new hit arrives, so rapid hits keep it going.

2. A black-and-white flashback with slow motion

Section titled “2. A black-and-white flashback with slow motion”

A flashback cuts to another camera whose look is Sepia, Noise and Vignette, and slows the game down. After eight seconds of real time it cuts back.

Flashback.jx
#pragma lifecycle(startup)
let busy = false;
function startup() {
on('story/flashback', async () => {
if (busy) return;
busy = true;
CameraDirector.switchTo('Flashback Cam');
Time.scale = 0.5;
const start = Time.now();
while (Time.since(start) < 8000) {
await new Promise((done) => delay(done, 100));
}
Time.scale = 1;
CameraDirector.switchToMain();
busy = false;
});
}
  • The Flashback Cam camera entity carries its own effects, set up in the editor. CameraDirector.switchTo cuts to it, and its effects show from the same frame.
  • Time.scale = 0.5 runs the game at half speed. delay counts game time, so the loop measures real time with Time.now() and Time.since() to keep the flashback eight real seconds long.
  • CameraDirector.switchToMain() cuts back to the main camera and its own look.
  • The busy flag ignores a second flashback while one is playing.

Four colour effects on one camera make five looks. Each press of Space changes their props to the next look.

ColourGrades.jx
#pragma lifecycle(startup, update)
const LOOKS = [
{ name: 'Natural', hue: 0, saturation: 0, sepia: 0, grey: 0, darkness: 0.3 },
{ name: 'Vivid', hue: 0, saturation: 0.6, sepia: 0, grey: 0, darkness: 0.4 },
{ name: 'Old photo', hue: 0, saturation: -0.3, sepia: 0.9, grey: 0, darkness: 0.7 },
{ name: 'Noir', hue: 0, saturation: 0, sepia: 0, grey: 1, darkness: 0.85 },
{ name: 'Alien', hue: 120, saturation: 0.3, sepia: 0, grey: 0, darkness: 0.5 },
];
let index = 0;
let hueSaturation;
let sepia;
let grayscale;
let vignette;
function apply(look) {
hueSaturation.setProps({ hue: look.hue, saturation: look.saturation });
sepia.setProps({ intensity: look.sepia });
grayscale.setProps({ intensity: look.grey });
vignette.setProps({ darkness: look.darkness });
log('Look:', look.name);
}
function startup() {
const eye = findEntity('Main Camera');
hueSaturation = eye.getComponent(HueSaturationEffectComponent);
sepia = eye.getComponent(SepiaEffectComponent);
grayscale = eye.getComponent(GrayscaleEffectComponent);
vignette = eye.getComponent(VignetteEffectComponent);
apply(LOOKS[index]);
}
function update() {
if (!Input.keyboard.isKeyReleased(Key.Space)) return;
index = (index + 1) % LOOKS.length;
apply(LOOKS[index]);
}
  • All four effects stay on the camera; a look only changes their props, so switching costs no rebuild.
  • An intensity of 0 leaves Sepia and Grayscale with no visible effect, and a saturation of 0 leaves colours unchanged.
  • Each look is plain data, so adding one is a single line in LOOKS.