fork download
  1. std::vector<sf::Sprite> loadSprites(std::string name,
  2. int width = 64,
  3. int height = 64,
  4. int alpha = 255,
  5. bool transparent = false){
  6.  
  7. std::vector<sf::Sprite> vec;
  8. sf::Image spbase;
  9. sf::Texture tx;
  10. sf::IntRect area;
  11.  
  12. if(!spbase.loadFromFile(name)){
  13.  
  14. return vec;
  15. }
  16.  
  17. if(transparent){
  18.  
  19. sf::Color c = spbase.getPixel(0, 0);
  20. c.a = alpha;
  21. spbase.setPixel(0, 0, c);
  22. }
  23.  
  24. for(int y = 0; y < spbase.getSize().y; y+= height){
  25. for(int x = 0; x < spbase.getSize().x; x += width){
  26.  
  27. area = sf::IntRect(x, y, width, height);
  28.  
  29. tx.loadFromImage(spbase, area);
  30. vec.push_back(sf::Sprite(tx));
  31. }
  32. }
  33. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty