Skip to content

Colors

Colors are a key part of making your game visually appealing. In the Saxion Game App, we can define colors, store them by name, and use them for drawing shapes or clearing the screen.

Instead of remembering RGB values for every color, we can give each color a name. This makes your code easier to read, easier to maintain and reusable across multiple shapes and screens.

Colors don't have to be disposed (unlike textures, sounds, etc.).

GameApp.addColor("skyBlue", 135, 206, 235);
GameApp.addColor("grassGreen", 34, 139, 34);

Default colors

By default we have already loaded a whole set of colors that you can use out of the box. We have chosen to use the Tailwind color palette, which is normally used for webdevelopment. The nice thing about this palette is that it consists of colors and shades. You can easily make a specific color lighter or darker.

The default color for each specific color has shade 500. So blue-500 is the normal blue color.

  • If you want to make the color darker, you go to a higher shade (e.g. blue-600).
  • If you want to make the color lighter, you go to a lower shade (e.g. blue-400).

For each available color, the following shades are available: 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950.

The colors white and black are also available. They don't have shades.

The following table gives you an overview of the available colors in the Saxion Game App, with the corresponding shades:

Shade Slate Gray Zinc Neutral Stone Red Orange Amber Yellow Lime Green Emerald Teal Cyan Sky Blue Indigo Violet Purple Fuchsia Pink Rose
50 slate-50 gray-50 zinc-50 neutral-50 stone-50 red-50 orange-50 amber-50 yellow-50 lime-50 green-50 emerald-50 teal-50 cyan-50 sky-50 blue-50 indigo-50 violet-50 purple-50 fuchsia-50 pink-50 rose-50
100 slate-100 gray-100 zinc-100 neutral-100 stone-100 red-100 orange-100 amber-100 yellow-100 lime-100 green-100 emerald-100 teal-100 cyan-100 sky-100 blue-100 indigo-100 violet-100 purple-100 fuchsia-100 pink-100 rose-100
200 slate-200 gray-200 zinc-200 neutral-200 stone-200 red-200 orange-200 amber-200 yellow-200 lime-200 green-200 emerald-200 teal-200 cyan-200 sky-200 blue-200 indigo-200 violet-200 purple-200 fuchsia-200 pink-200 rose-200
300 slate-300 gray-300 zinc-300 neutral-300 stone-300 red-300 orange-300 amber-300 yellow-300 lime-300 green-300 emerald-300 teal-300 cyan-300 sky-300 blue-300 indigo-300 violet-300 purple-300 fuchsia-300 pink-300 rose-300
400 slate-400 gray-400 zinc-400 neutral-400 stone-400 red-400 orange-400 amber-400 yellow-400 lime-400 green-400 emerald-400 teal-400 cyan-400 sky-400 blue-400 indigo-400 violet-400 purple-400 fuchsia-400 pink-400 rose-400
500 slate-500 gray-500 zinc-500 neutral-500 stone-500 red-500 orange-500 amber-500 yellow-500 lime-500 green-500 emerald-500 teal-500 cyan-500 sky-500 blue-500 indigo-500 violet-500 purple-500 fuchsia-500 pink-500 rose-500
600 slate-600 gray-600 zinc-600 neutral-600 stone-600 red-600 orange-600 amber-600 yellow-600 lime-600 green-600 emerald-600 teal-600 cyan-600 sky-600 blue-600 indigo-600 violet-600 purple-600 fuchsia-600 pink-600 rose-600
700 slate-700 gray-700 zinc-700 neutral-700 stone-700 red-700 orange-700 amber-700 yellow-700 lime-700 green-700 emerald-700 teal-700 cyan-700 sky-700 blue-700 indigo-700 violet-700 purple-700 fuchsia-700 pink-700 rose-700
800 slate-800 gray-800 zinc-800 neutral-800 stone-800 red-800 orange-800 amber-800 yellow-800 lime-800 green-800 emerald-800 teal-800 cyan-800 sky-800 blue-800 indigo-800 violet-800 purple-800 fuchsia-800 pink-800 rose-800
900 slate-900 gray-900 zinc-900 neutral-900 stone-900 red-900 orange-900 amber-900 yellow-900 lime-900 green-900 emerald-900 teal-900 cyan-900 sky-900 blue-900 indigo-900 violet-900 purple-900 fuchsia-900 pink-900 rose-900
950 slate-950 gray-950 zinc-950 neutral-950 stone-950 red-950 orange-950 amber-950 yellow-950 lime-950 green-950 emerald-950 teal-950 cyan-950 sky-950 blue-950 indigo-950 violet-950 purple-950 fuchsia-950 pink-950 rose-950

Registering colors

Currently the application has support for RGB and RGBA colors. You can add colors by providing the integer values for your colors. It is also possible to use the Color class from LibGDX.

If you add a color that already exists, then it is being replaced with the new color.

// Register the color red
GameApp.addColor("red", 255, 0, 0);

// Register a semi transparent color (50% transparent)
GameApp.addColor("semiTransparentRed", 255, 0, 0, 128);

// Instead of using the RGB values, we can also directly use the Color class from LibGDX
GameApp.addColor("skyBlue", new Color(0.53f, 0.81f, 0.92f));

Drawing with colors

GameApp.setColor("semiTransparentRed");
GameApp.drawRect(50, 50, 100, 50);

// Or directly
GameApp.drawRect(50, 50, 100, 50, "semiTransparentRed");

Clearing the screen with a color

Clear the contents of the whole screen with a color by using the clearScreen() method.

GameApp.clearScreen("skyBlue");

Check if a color exists

if (GameApp.hasColor("grassGreen")) {
    System.out.println("Color is registered!");
}

List all colors

String[] allColors = GameApp.getAllColors();

Transparency

Some colors can be partially transparent. For example:

GameApp.addColor("semiTransparentRed", 255, 0, 0, 128); // 50% transparent

The Alpha value controls transparency:

  • 255 = full opaque
  • 128 = half transparent
  • 0 = invisible

Important: To see transparency, you must enable it before drawing:

@Override
public void render(float delta) {
    super.render(delta);
    GameApp.clearScreen("white");

    // Turn on transparency rendering
    GameApp.enableTransparency();
    GameApp.startShapeRenderingFilled();
    GameApp.setColor("semiTransparentRed");
    GameApp.drawRect(50, 50, 100, 50);
    GameApp.endShapeRendering();
    // Optional: turn off transparency
    GameApp.disableTransparency();
}