gamemaker将画布信息存入buffer

230 Views

surface_set_target(_surf);
{
draw_clear_alpha(c_black,0);
draw_sprite(_sprite,i,0,0);
}
surface_reset_target();
//Find all unique colors
var _buff = buffer_create(_sprite_width*_sprite_height*4, buffer_fixed, 4);
buffer_get_surface(_buff, _surf, 0, 0, 0);
for(var _x=0; _x<_sprite_width; _x++)
{
for(var _y=0; _y<_sprite_height; _y++)
{
var _col = buffer_read(_buff, buffer_u32);
var _a = (_col >> 24) & 255;
var _r = (_col >> 16) & 255;
var _g = (_col >> 8) & 255;
var _b = _col & 255;
var _col=make_colour_rgb(_r, _g, _b);
if(ds_list_find_index(_temp_colors,_col) == -1)
{ //First time encountering this color for this sprite.
ds_list_add(_temp_colors,_col);
if(ds_list_find_index(Unique_Colors,_col) == -1)
{ //First time across all sprites.
_new_color_count++;
//But don't add it yet... need to make sure it doesn't make us
//Go over the limit.
}
}
}
}
///Save Sprite
ds_list_add(_sprite_list,sprite_create_from_surface(_surf,0,0,_sprite_width,_sprite_height,false,false,0,0));
buffer_delete(_buff);

0 回复

发表评论

Want to join the discussion?
Feel free to contribute!

发表评论

电子邮件地址不会被公开。 必填项已用*标注