Change sprite color in runtime

0 favourites
  • 10 posts
From the Asset Store
Gather the balls with the same color and earn as much score as you can!
  • Hello, How do i change the color of a sprite(white drop) during gameplay? I want to change for blue for example when my sprite collide with other object.

    I've seen other posts about Set RGB color in action, using shaders effects (.fx) files, but i can'nt found none of these options in my Construct2 IDE.

    Is it possible?? Thanks

  • nope, fx are for construct classic

  • damn.... any way to do the same thing with Construct 2?

  • You have two possibilities:

    You could create alternative colored images for every picture you have. Kind of a pain though.

    What I would do is:

    1. Create a bunch of solid colored blocks in paint.

    2. Make the block be wider and longer than any sprite you intend to use it with.

    3. Load all of these into a single sprite called OVERLAY on different frames, set animation speed to 0, and give this sprite a pinnable behavior.

    4. Write a bunch of global variables COLOR_RED, COLOR_BLUE, COLOR_GREEN which numerical values correspond to the OVERLAY's respective frame.

    Whenever you want to change a sprite's color, simply do the following:

    1. Have that sprite spawn an OVERLAY

    2. Set OVERLAY frame to the appropriate color

    3. set its effect to ADDITIVE

    4. Pin it to the sprite (assuming origin is the middle point of that sprite).

    You can destroy it later, or change its visibility, etc.

    Hope this helps,

    -- cacotigon

    EDIT: I whipped up a quick capx file to demonstrate it:

    Color overlay capx project

  • Its rather complicated, but you could, in theory, use the Canvas plug as a mask.

    You would have to do a nested loop to compare rgb values, like if rgbaAt loopx,loopy = 255,0,0, canvas draw point at loopx,loopy, color 0,255,0.

    Of course you would have to repeat the loop for each additional color you want to change.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Pile of barf bags. I forgot with my solution you'd have to worry about other overlapping sprites and pictures and backgrounds. HERP DURP DURP.

    EDIT:

    If you were willing to create solid color "cut-outs" (like masks) of all the animation frames, you could do the pin, making sure to update the overlay frame to correspond to the currently displayed sprite frame. The only benefit to this approach versus just making a copy of all the sprites frames in the colors you want would be that you can combine multiple overlays with additive properties at once allowing for blends or combinations, or change the opacity of the overlay without affecting the main sprite's opacity.

  • Thanks guys, i'm gonna considerate all solutions, i'm gonna run some tests to see whats fits best in my game.

    Thansk for the help. sse ya

  • It is worth stating that Scirra is planning on adding WebGl pixel shaders - I assume colouring will be included eventually.

  • U can do it now.

    Just add effect "setColor"

  • hobibit of all of the options above yours seems like the most straightforward, however I just posted my issue with set color.. there must be a solution, i just can't figure out what could be difference. the objects are frames of animation in sprite object so they are all in the same family..

    The only thing I can think of is that maybe since my sprite object frames are white, the white is somehow bleeding through, but if that were the case it would seem like all of them would be a little washed out and that's not the case.

    I feel like set color is the best solution, but i can't figure out why it look this way.

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