How do I use hex colour values in my code?

0 favourites
  • 4 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • I want to import colour palettes from a JSON file and I find it much tidier to have a single hex value to represent each colour rather than an array of 3 different values (rgb).However, I can seem to find any way in C3 to set colour using Hex values(in code)). (only RGB)

    I figured the best way would be to write a little converter in Javascript, but even though I have the new converted values as an array (eg rgb_array = [r,g,b];) I dont know how to get this back from my Javscript into construct. I can only set values of variables in Construct that are strings, numbers or booleans.

    Cheers

    p.S I tried the plugin called 'CONVERTERCOLORJS (AIOUTE GAO)' but using the following:

    Set Color Colour_Converter.toRGB("#e4646e")

    Didnt do anything to the colour.

    Tagged:

  • Here's an event based way

    https://www.dropbox.com/scl/fi/0zafmr4lyclg3mmcodkea/hex2color.c3p?rlkey=6ird9o8ud8opsp2k3v7chtb3x&dl=1
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here's an event based way

    https://www.dropbox.com/scl/fi/0zafmr4lyclg3mmcodkea/hex2color.c3p?rlkey=6ird9o8ud8opsp2k3v7chtb3x&dl=1

    Thank you Rojo, this is super helpful! ❤️

  • Thanks so much for this. Very useful! I tested it and ran into a slight issue. The code you sent doesn't account for the # character so if your hex has a # character the resulting colours will be very green.

    If your hex numbers contain # symbols you might want also to add the following line to trim it from the string first:

    set hex to replace(hex, "#", "")

    This way both formats will work. eg 0000ff and #0000ff

    I have attached screenshot..

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)