How to pass color to an asset dynamically?

0 favourites
  • 5 posts
From the Asset Store
Assets for creating mountains and ravines environments
  • Hello everyone, I have the following problem.

    I try to set the color of an asset dynamically, I set the ajax, the server in the json passes me some values which I also pass in a global variable to see if it passes and passes them, but the color does not set. it turns black for me.

    I used the following syntax: JSON.Get(".background_rgb").

    i also had two response types set:

    1) background_hex"

    2) background_rgb.

    despite i choose either way it doesn't set the color. how can i fix it?

    Thank you very much.

    Tagged:

  • Try JSON.Get("background_rgb") without the dot.

    If it doesn't help, please post the full JSON string.

    Also, you can't just use a number to set color in C3, unless you encode it properly. You need to use one of these expressions - rgbex, rgbex255, rgba, rgba255

    For example: rgbex255(0,255,0) is 100% green.

  • Hi, thanks for reposting. i tried as you said but it doesn't set anything. I will try to get the response set with: "rgbex255(4, 170, 109)" and see if it sets it. Anyway the snippent of the code is in the screen I attach the answer is as follows:

    {

    "message": {

    "content": {

    "title": "Tutto ok!",

    "title_color": "#00000",

    "title_dim": "1.2em",

    "descr": "Fallo passare va!",

    "descrColor": "#00000",

    "descr_dim": "0.8em",

    "background_hex": "#04aa6d",

    "background_rgb": "rgb(4, 170, 109)"

    }

    }

    }

    thank you very much!

  • So the correct path is "message.content.background_rgb"

    Also, you can't send "rgb(4,107,109)" in JSON, because it's a string. Well, you can, but then you will have to parse it into three individual numbers 4, 107 and 109..

    So you need to send three separate numbers - "background_r":4, "background_g":107, "background_b":109. And then use this code to set color:

    JSON Set Path to "message.content"
    Sprite set color to rgbex255(JSON.Get(".background_r"), JSON.Get(".background_g"), JSON.Get(".background_b"))
    

    Another option is to pre-generate the rgb colors which Construct will understand and send them from the server. For example, if you run this small event

    TextInput Set Text to rgbex255(4,107,109)
    

    ... you will see that it returns the number -4405244385279. So you can just send this number in JSON key "background_rgb" and then use this:

    JSON Set Path to "message.content"
    Sprite set color to JSON.Get(".background_rgb")
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • with the syntax you suggested with adding the full path works great! thank you so much for the support!!!

    i leave the snippet of the code i used.

    rgbex255(JSON.Get(".message.content.background_r"), JSON.Get(".message.content.background_g"), JSON.Get(".message.content.background_b"))

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