Asset - Graphics sprite_getpixel (Sprite Pixel Data)

matharoo

manualman
GameMaker Dev.
Matharoo presents...


sprite_getpixel

sprite_getpixel() gets the color of a sprite's pixel.

• Returns the data in an array, in RGBA order.

• Values are in the 0-255 range.

• Uses buffers, which are fast!

• Automatically handles buffer creation & usage, so it only has to go through the "sprite -> surface -> buffer" process ONCE for each image, resulting in reduced processing overhead.

Usage example:

Code:
var arr = sprite_getpixel(sBoi, 0, 2, 4); // (sprite, subimg, x, y)

var color = make_color_rgb(arr[0], arr[1], arr[2]);
var alpha = arr[3]/255;
Read the documentation present inside the Scripts for usage instructions.
 
Last edited:
S

SayBaconOneMoreTime

Guest
I literally just got done writing the equivalent of this for my game. Thanks matharoo. Right on time. /sarcasm
 

matharoo

manualman
GameMaker Dev.
Useful to have.
Hey, why not use pragma 'global' to call sprite_data_begin?
Hey! I don't understand how that works, so I read the doc page...
Nocturne said:
Code:
gml_pragma("global", "scr_Init()");
This will call the script "scr_Init" before the first room of the game is run.
So, are you saying that the user will have to use that function instead of sprite_data_begin()? Or... will they not have to, as it will automatically run? I don't understand. :)
 
C

Captaintoottoot

Guest
The asset gives errors on compile now. The errors are in the attached image. Any idea how to fix it?
 

Attachments

Last edited by a moderator:

matharoo

manualman
GameMaker Dev.
The asset gives errors on compile now. The errors are in the attached image. Any idea how to fix it?
Weird; it's saying that those functions don't exist while they do exist. Make sure you aren't using a really old version of GMS.

Try cleaning the asset compiler cache and restarting GM. If it still persists, submit a bug report to YoYo.
 
Top