Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```var _sprite=sprite_add(_file,_frames,_remove_back,false,0,0);
- //Need to break out all sprites into their own sprites.
- var _temp_colors=ds_list_create(); //Stores all unique colors for this sprite.
- var _new_color_count=0;
- var _sprite_list=ds_list_create();
- var _sprite_width,_sprite_height;
- _sprite_width=sprite_get_width(_sprite);
- _sprite_height=sprite_get_height(_sprite);
- var _surf=surface_create(_sprite_width,_sprite_height);
- for(var i=0;i<sprite_get_number(_sprite);i++)
- { //Loop through, draw each sprite to a surface of a standard size.
- //Then create a new sprite for each surface.
- //Pull all unique colors out of the sprite.
- //Save Sprite in Sprite_List for management
- show_debug_message("Examining sprite: "+string(i));
- 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(_a == 0)
- continue;
- /*if(_col==c_black)
- {
- continue;
- }*/
- 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);
- }
- surface_free(_surf);
- sprite_delete(_sprite);```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement