Can you use variables with Game.GetColorFromRGB?

Started by CaptainD, Fri 27/07/2018 23:16:16

Previous topic - Next topic

CaptainD

I've been trying to use variables with this command but the results appear to bear no resemblance to what they should.  Basically I have:

Code: ags
c=Game.GetColorFromRGB(r, g, b);


r, g and b are integers ranging from 0-255, and I then set the surface drawing colour to c.  Obviously I'm doing something wrong, or I'm simply trying to do something that can't be done with this command.  Any ideas?
 

Crimson Wizard

This is the correct way of using this commmand, and there is absolutely no difference whether you use literal numbers or variables there. But I could not understand what the problem exactly is from your explanation. Can you give more details - what do you expect, and what do you get?

morganw

The colour is an integer, so unless you've already declared it:
Code: ags
int c = Game.GetColorFromRGB(r, g, b);

CaptainD

morganw - yes I've set C as a variable.

CW - the problem is that the colours are nothing like what I'd expect.  So for instance R=0 G=0 B=0; each game cycle draws a circle and increments b by 1; I'd expect to see a gradually brightening blue colour.  However the colours are all over the place, they don't even have a predominance of blue to them.  Also it appears to be using a very limited colour palette no matter what colour depth I set the game to.




Essentially this is the code that's doing this part every loop.  Nothing fancy at all.

Code: ags
c=Game.GetColorFromRGB(r, g, b);
   
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = c;
surface.DrawCircle(x,y, size);
surface.Release();

b++;

if (b>255) b=0;


I just don't get what I'm doing wrong, but clearly I'm doing something wrong!
 

Crimson Wizard

#4
I do not remember if this was documented, but certainly mentioned on forums few times before.

The first several (16 or 32) color indexes in AGS are special system colors, and I think you need to start Red and Green with 4 to avoid using them.
In other words, iterate Red and Green from 4 to 255, and blue from 0 to 255.

EDIT: This is mentioned on the Color Picker pane in AGS. The only color that needs to be restricted to 4+ is Green.

So, Green must go from 4 to 255, other components may be from 0 to 255.


SMF spam blocked by CleanTalk