How do I change color of a sprite based off of an array value?

0 favourites
  • 4 posts
From the Asset Store
Color all tiles with the same color in 22 moves or less!
  • Hi! So, I'm making a game that's basically like flipnote studio. An animation tool. But beefed up and is real cool. So, the game works by generating pixels on a 1080x1080 area in the center, generating pixels of 108x108 area. My plan is to have the pixels reference off of a 108x108 array for its color, and the user can write to that array, and the pixels will re-render the canvas to show the changes. That's the basics of the drawing mechanic. The X and Y axes will be the pixels' color, and the Z axis will indicate the different frames. It starts by just going to 0,0 and cloning pixels across the area.

    Even though I haven't found a reliable way to render the canvas real quickly, the main thing I want to stress on is how the pixels will change color? If I manually enter something to get a diagonal gradient (for example, the color "blue" will change based on what X and Y value it is. The more they are, the stronger blue it will be) and it works! But no matter how hard I try, everything is always black when I try to read values off of the array. All the values are set to be like "000,000,000" and some are set to "1000,000,000" but nothing happens. Not even when I changed the array to a simple "0" to indicate black and white instead of color.

    Can anyone help me on how I can read color from an array and apply it on the respective pixel? Let me know if something is unclear or not mentioned. Thanks!

  • To quote the tips for this forum:

    "SHARE YOUR PROJECT

    It's difficult to help if you merely describe your project, or even if you post a screenshot of your events. It's much better to share your actual project, which is normally a .c3p file."

  • Like Fengist said, it's hard to guess the problem without a code to check. But, it may be that you are asigning string values instead of numbers when trying to set the colors. If each array is a string, like "123,45,98", you must, first convert those to numbers using int(value).

    For instance if you have "123,45,98" as a value.

    Instead of using "set color" to

    rgbEx(array.At(x,y))

    You must get each of those and convert to integer. Something like this

    rgbEx(tokenat(array.At(x,y), 0, ","),tokenat(array.At(x,y), 2, ","),tokenat(array.At(x,y), 2, ","))

    Maybe the problem has nothing to do with this, but it's a guess since I have no access to you code.

    Cheers!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Like Fengist said, it's hard to guess the problem without a code to check. But, it may be that you are asigning string values instead of numbers when trying to set the colors. If each array is a string, like "123,45,98", you must, first convert those to numbers using int(value).

    For instance if you have "123,45,98" as a value.

    Instead of using "set color" to

    rgbEx(array.At(x,y))

    You must get each of those and convert to integer. Something like this

    rgbEx(tokenat(array.At(x,y), 0, ","),tokenat(array.At(x,y), 2, ","),tokenat(array.At(x,y), 2, ","))

    Maybe the problem has nothing to do with this, but it's a guess since I have no access to you code.

    Cheers!

    Thanks for letting me know on the tokenat expression! That makes things much easier, I figured out what to do! And, I am sort of new to the forums in terms of asking for help, so I will keep in mind that I need to share my code. Thanks again!

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