Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mandle on Wed 10/11/2021 11:44:30

Title: Is it possible to read the color value of a pixel from the background of a room?
Post by: Mandle on Wed 10/11/2021 11:44:30
I seem to remember that I managed to do this before, but maybe I am mistaken.

I have a huge array that I want to fill with values each time the game starts and I thought that I might just be able to read them pixel by pixel from the room background as color codes.

Is this possible, and, if so, how?

I remember bashing my head up against dynamic sprites for hours before finally getting it working.

Something about GetPixel?
Title: Re: Is it possible to read the color value of a pixel from the background of a room?
Post by: Khris on Wed 10/11/2021 13:09:26
You need this:

Code (ags) Select
  DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
  int color = ds.GetPixel(x, y);
Title: Re: Is it possible to read the color value of a pixel from the background of a room?
Post by: Mandle on Wed 10/11/2021 13:14:12
Thanks so much, Khris!
Title: Re: Is it possible to read the color value of a pixel from the background of a room?
Post by: Crimson Wizard on Wed 10/11/2021 15:09:07
QuoteI have a huge array that I want to fill with values each time the game starts and I thought that I might just be able to read them pixel by pixel from the room background

If it's not a real room background, but the way for you to have data, you may also read image from a file or a sprite, using DynamicSprite.CreateFromFile/CreateFromExistingSprite. Then get pixels using its drawing surface, as in above example, and delete the image:

Code (ags) Select

DynamicSprite *spr = DynamicSprite.CreateFromFile("myfile,bmp");
// or
DynamicSprite *spr = DynamicSprite.CreateFromExistingSprite(100);

DrawingSurface* ds = spr.GetDrawingSurcace();
int color = ds.GetPixel(x, y);
ds.Release();

spr.Delete();
Title: Re: Is it possible to read the color value of a pixel from the background of a room?
Post by: Mandle on Thu 11/11/2021 01:24:04
Thanks, CW! This will also come in handy! I did this a long time ago with my Predators/Prey simulator but forgot how to.