Advertisement
Guest User

Untitled

a guest
Sep 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. ```var _sprite=sprite_add(_file,_frames,_remove_back,false,0,0);
  2.  
  3. //Need to break out all sprites into their own sprites.
  4. var _temp_colors=ds_list_create(); //Stores all unique colors for this sprite.
  5. var _new_color_count=0;
  6. var _sprite_list=ds_list_create();
  7. var _sprite_width,_sprite_height;
  8. _sprite_width=sprite_get_width(_sprite);
  9. _sprite_height=sprite_get_height(_sprite);
  10. var _surf=surface_create(_sprite_width,_sprite_height);
  11. for(var i=0;i<sprite_get_number(_sprite);i++)
  12. { //Loop through, draw each sprite to a surface of a standard size.
  13. //Then create a new sprite for each surface.
  14. //Pull all unique colors out of the sprite.
  15. //Save Sprite in Sprite_List for management
  16. show_debug_message("Examining sprite: "+string(i));
  17. surface_set_target(_surf);
  18. {
  19. draw_clear_alpha(c_black,0);
  20. draw_sprite(_sprite,i,0,0);
  21. }
  22. surface_reset_target();
  23. //Find all unique colors
  24. var _buff = buffer_create(_sprite_width*_sprite_height*4, buffer_fixed, 4);
  25. buffer_get_surface(_buff, _surf, 0, 0, 0);
  26. for(var _x=0; _x<_sprite_width; _x++)
  27. {
  28. for(var _y=0; _y<_sprite_height; _y++)
  29. {
  30. var _col = buffer_read(_buff, buffer_u32);
  31. var _a = (_col >> 24) & 255;
  32. var _r = (_col >> 16) & 255;
  33. var _g = (_col >> 8) & 255;
  34. var _b = _col & 255;
  35. var _col=make_colour_rgb(_r, _g, _b);
  36. if(_a == 0)
  37. continue;
  38. /*if(_col==c_black)
  39. {
  40. continue;
  41. }*/
  42. if(ds_list_find_index(_temp_colors,_col) == -1)
  43. { //First time encountering this color for this sprite.
  44. ds_list_add(_temp_colors,_col);
  45. if(ds_list_find_index(Unique_Colors,_col) == -1)
  46. { //First time across all sprites.
  47. _new_color_count++;
  48. //But don't add it yet... need to make sure it doesn't make us
  49. //Go over the limit.
  50. }
  51. }
  52. }
  53. }
  54. ///Save Sprite
  55. ds_list_add(_sprite_list,sprite_create_from_surface(_surf,0,0,_sprite_width,_sprite_height,false,false,0,0));
  56. buffer_delete(_buff);
  57. }
  58. surface_free(_surf);
  59. sprite_delete(_sprite);```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement