Is it possible to read the color value of a pixel from the background of a room?

Started by Mandle, Wed 10/11/2021 11:44:30

Previous topic - Next topic

Mandle

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?

Khris

You need this:

Code: ags
  DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
  int color = ds.GetPixel(x, y);


Crimson Wizard

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

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();

Mandle

Thanks, CW! This will also come in handy! I did this a long time ago with my Predators/Prey simulator but forgot how to.

SMF spam blocked by CleanTalk