此函数可用于使用表面的局部坐标 (其中 (0, 0) 为左上角) 获取表面特定像素的颜色。此函数不应经常使用,因为它非常慢并且可能会导致游戏暂停。
此函数返回的数据类型将取决于给定表面 的格式:
格式 | 函数返回 |
---|---|
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. |
注意 在处理表面时,由于表面存储在纹理内存中,因此它们可能随时不再存在。在直接引用表面之前,您应该 始终 使用 surface_exists 检查表面是否存在。
surface_getpixel(surface_id, x, y);
参数 | 类型 | 描述 |
---|---|---|
surface_id | Surface | 表面。 |
x | Real | 表面上获取像素的 x 位置。 |
y | Real | 表面上获取像素的 y 位置。 |
col = surface_getpixel(surf, 56, 78);
这将返回变量 surf 中存储的表面坐标 (56, 78) 处的像素颜色。