How to generate random color and change sprite color runtime

Get help using Construct 2

Post » Sun May 15, 2016 3:33 am

Hello
is there anyway to generate random color and change a sprite color in run-time ?
after some researches I found a way to put effect and change it (and this supported in webGL only)
any alternative way to change it ?
B
16
S
6
G
2
Posts: 31
Reputation: 2,196

Post » Sun May 15, 2016 3:35 am

How about you make multiple frames for the sprite?

Set the Default animation speed to 0 and randomize the current frame of the sprite using Set animation frame action with floor(random(Self.AnimationFrameCount)))
B
103
S
24
G
11
Posts: 695
Reputation: 12,884

Post » Sun May 15, 2016 3:50 am

Tetriser wrote:How about you make multiple frames for the sprite?

Set the Default animation speed to 0 and randomize the current frame of the sprite using Set animation frame action with floor(random(Self.AnimationFrameCount)))


I'll try it
B
16
S
6
G
2
Posts: 31
Reputation: 2,196

Post » Sun May 15, 2016 5:11 am

Hey @frodoe7, :)

Another similar method is to use multiple sprites stacked together.

Suppose you have a tank in your game, and you want to be able to change the color of the body, the treads, and the turret separately.
One way to do this is to create a sprite for the body, a sprite for the treads, and a sprite for the turret, and for each one include color variations. The variations can either be in frames as @Tetriser suggested, or in their own separate animations within the sprite.
You can then use the "Pin" behavior to keep all the sprites together.

This approach can be especially handy if you want to allow for a lot of variations, as the number of color combinations is the product (multiplicative total) of the number of color variations in each sprite.

So if the tank has 8 colors for each sprite (body, treads, and turret), then the total number of color arrangements is 8 * 8 * 8, which is 512 combinations. It adds (multiplies) up fast. :)
B
26
S
17
G
8
Posts: 323
Reputation: 6,021

Post » Sun May 15, 2016 3:04 pm

but we still here
I need for example to generate a totally random color (don't know it previously) and assign it to my sprite
I can write C2 plugin for that with JS , bu how to access the sprite image ?
B
16
S
6
G
2
Posts: 31
Reputation: 2,196


Return to How do I....?

Who is online

Users browsing this forum: Exabot [Bot] and 6 guests