Palettes - mgismissing/cosmos GitHub Wiki
Palettes provide an optional layer of abstraction over the vanilla palette management system, where the palette has to be redefined every time a modification is required (see the MakeCode Arcade palette documentation).
Managing the palette system
Since this palette system completely changes the vanilla palette system, it is possible to just disable it altogether:
Palette.disable()
When palettes are disabled every call to Palette.load
and Palette.free
are simply ignored. Palette.abs_id
will still return the correct color id for compatibility reasons.
The desired palette should also be reapplied.
To enable it again, it's as simple as running:
Palette.enable()
system.palette.apply()
Creating palettes
Keep in mind that the maximum number of palettes loaded at the same time is 5 due to hardware limitations. You can circumvent this issue by dynamically load
ing palettes and then free
ing them when you don't need them anymore.
Normally, the mouse cursor and other system resources take their colors from palette 0. To change this palette's colors, the system palette must be free
d and another custom one load
ed right after:
system.palette.free()
myPalette.load(0)
To create (and load) a custom palette:
let myTheme: number[] = [0x007f00, 0x00ff00, 0x7fff7f]
let myPalette: Palette = new Palette(myTheme)
myPalette.load(1)
// under normal conditions, slot 0 will be taken by the system palette,
// leaving us with slots 1, 2, 3 and 4.