Change sprite color in runtime

Get help using Construct 2

Post » Tue Jan 31, 2012 1:55 am

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
B
3
Posts: 7
Reputation: 389

Post » Tue Jan 31, 2012 9:24 am

nope, fx are for construct classic
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Jan 31, 2012 9:27 pm

damn.... any way to do the same thing with Construct 2?
B
3
Posts: 7
Reputation: 389

Post » Tue Jan 31, 2012 9:44 pm

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 projectcacotigon2012-01-31 22:03:21
B
30
S
6
G
8
Posts: 232
Reputation: 6,119

Post » Tue Jan 31, 2012 10:16 pm

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.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Tue Jan 31, 2012 10:31 pm

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.
cacotigon2012-01-31 22:40:31
B
30
S
6
G
8
Posts: 232
Reputation: 6,119

Post » Tue Jan 31, 2012 10:42 pm

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
B
3
Posts: 7
Reputation: 389

Post » Wed Feb 01, 2012 2:15 am

It is worth stating that Scirra is planning on adding WebGl pixel shaders - I assume colouring will be included eventually.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Tue Sep 23, 2014 9:35 am

U can do it now.
Just add effect "setColor"
B
19
S
3
Posts: 67
Reputation: 1,426

Post » Mon Jan 26, 2015 6:56 pm

@hobibit of all of the options above yours seems like the most straightforward, however I just posted my issue with set color.. viewtopic.php?f=147&t=123505&p=878382#p878382 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.
B
51
S
7
G
1
Posts: 869
Reputation: 5,943

Next

Return to How do I....?

Who is online

Users browsing this forum: blackhornet, mjj1990 and 7 guests