YoYo Games Wiki

Getting the number of blue pixels on the screen

From YoYoGames Wiki

Getting the number of blue pixels on the screen in Game Maker is an example on the return function of Game Maker, that is used in Script.

Explanation

What the script should do is make a loop that would check the color of each pixel on the room. To do that, we shall check one row at a time, then move on to the next row.

The Code

width=room_width;
height=room_height;
current_x=0;
current_y=0;
blue_pixels=0;
repeat(height)
{
	repeat(width)
	{
		current_pixel_color=draw_getpixel(current_x,current_y);
		if current_pixel_color==c_blue
		{
			blue_pixels+=1;
		}
	}
 	current_y+=1;
	current_x=0;
}
return blue_pixels;