Any way to get the color ?

Discussion and feedback on Construct 2

Post » Wed Jan 25, 2017 8:10 am

Hey Constructors,

Just a little question. Is there any way (third party or not) to get a sprite's color ? I was thinking of a good way to improve some stuff in the little game I'm currently working on, and until now, I was dealing with several families. One family stands for one color. If I need to know if the player stands on a purple, red, or orange platform, all I have to do is to check if the said platform belongs to the red, purple or orange family. Done. It works, but hell, as soon as my level begins to be a little more complex it takes some times to put every sprites in every matching families. Thus, if I could detect the color itself directly, that'd be great. I'm picturing this as something like this, for example :

If the character is standing on a sprite with a color between #HexDeciValue and #HexDeciValue then apply this bonus/malus

Do you know any way to achieve something like this ?

If you have any idea to improve my mechanic, don't be shy, I'll take it too ! Please know that I don't ask this in the How do I section because I don't think there is a native feature to deal with that in C2 for the moment. I may be wrong of course, and if I am, sorry, wrong post, wrong place. Thanks !
B
16
S
4
Posts: 86
Reputation: 1,525

Post » Wed Jan 25, 2017 11:29 am

There is this:
color-of-a-pixel_p946044?#p946044

Thers is de canvas plugin that has this rgbaAt expression.
plugin-span-class-posthilit-canvas-span_p549487?#p549487

Personaly i think that you take this 'problem' as to strict. 'colour' can be presented as an instance variable (or family variable). Either as a string or as a number. Use the variable to pick.

If you choose to present the colors with a number, you can (to make it yourself easy) create a event sheet without an assigned layout, and include that in your main sheet. Create global variables there like:
Global variable 'cPurple' ... value 1
Global variable 'cBlue' ... value 2

Now if you gonna compare, it is easier to wrap your mind around it.
if instance variable = cBlue ... then

You can also set the animation speed to zero. (if you dont have animations). Now you make frames that match with the numbers. Frame 1 = Purple. Frame 2 is Blue.
Now you only deal with instances of the same Sprite. And do things like:

Mouse > object clicked > sprite
Sprite > compare frame > =? > Cblue
............. actions
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jan 28, 2017 10:46 am

Hello, thanks for replying, I'm gonna try that as soon as I can !
B
16
S
4
Posts: 86
Reputation: 1,525

Post » Sat Jan 28, 2017 11:30 am

I was in need of a similar logic in my project and I solved that by creating different animations for each color. In my code I get the color simply by referring to the object's animation name.
B
135
S
33
G
17
Posts: 1,557
Reputation: 20,721

Post » Thu Feb 02, 2017 5:07 am

Personally...I would create one platform family. all platforms of all colors would go into it.

Each platform object would have a instance variable "Color"

that way my code would read something like this:

player collision with platform
if(platform.color==1) Do this
else if(platform.color==2) Do something else.
B
28
S
8
G
1
Posts: 226
Reputation: 2,865


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 6 guests