surface_getpixel

This function can be used to get the colour of a specific pixel from a surface, using the local coordinates of the surface where (0, 0) is the top left corner. This function should not be used very often as it is extremely slow and may cause a pause in your game.

The data type returned by this function will depend on the format of the given surface:

FormatsFunction Return
surface_rgba8unorm (default)
surface_rgba4unorm
surface_r8unorm
surface_rg8unorm
For these formats, the function will return a regular colour value. Any unused channels are set to 0.
surface_rgba16float
surface_r16float
surface_rgba32float
surface_r32float
For these formats, the function will return an array with 3 values (R, G, B) with each being a 32-bit float. Any unused channels are set to 0.

To get the pixel colour with the alpha channel, use surface_getpixel_ext.

NOTE When working with surfaces there is the possibility that they can cease to exist at any time due to them being stored in texture memory. You should ALWAYS check that a surface exists using surface_exists before referencing them directly.

 

Syntax:

surface_getpixel(surface_id, x, y);

ArgumentTypeDescription
surface_idSurfaceThe surface.
xRealThe x position on the surface to get the pixel from.
yRealThe y position on the surface to get the pixel from.

 

Returns:

Colour or Array

 

Example:

col = surface_getpixel(surf, 56, 78);

This will return the colour of the pixel at coordinates (56, 78) of the surface stored in the variable surf.