Create a Background with Vertical Lines of Different Colours

Posted by in Software

I’ve got a list of colours (RGB) in an array and I want to build a background with vertical lines, each representing a colour from my list.

The process is too simple to put in a TL;DR 🙂

If my list of colours is, Array<Vector3> cols, then the process is as follows:

  • Create a pixmap:

  • Set one pixel with the corresponding colour in the list:

  • Create a texture off the pixmap:

  • Create a Sprite and resize it:

    This will create a sprite as large as your screen.

    Note: You’ll need to declare the sprite as a class member because you need to use it in render() .

  • In render() / draw() , render 🙂 :

Now, when you render, you’ll get the striped background.

Horizontal stripes

If you want horizontal stripes, then all you need to do is to create a vertical pixmap:

and fill it up accordingly (hint: invert the coordinates in drawPixel() ).

Note: The code above is taken from an Actor code.


A little experiment: If you find this post and ad below useful, please check the ad out 🙂