Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- void make_grid(sf::RenderTexture *text, const sf::Vector2f &size, const sf::Vector2f &cell_size)
- {
- for (unsigned x = 0; x < size.x; ++x)
- {
- for (unsigned y = 0; y < size.y; ++y)
- {
- sf::RectangleShape cell(cell_size-sf::Vector2f(2,2)); //Начало нанокостыля.
- cell.setPosition(sf::Vector2f(x*cell_size.x+1, y*cell_size.y+1)); //Нано-костыль дабы не рисовать снаружи еще один рект.
- cell.setOutlineThickness(1);
- cell.setOutlineColor(sf::Color::Black);
- cell.setFillColor(sf::Color(0, 0, 0, 0));
- text->draw(cell);
- }
- }
- }
- int main()
- {
- const sf::Vector2f grid_size(4,4); //Количество и размер ячеек.
- const sf::Vector2f cell_size(64, 64);
- sf::RenderTexture FT;
- FT.create(grid_size.x*cell_size.x, grid_size.y*cell_size.y);
- make_grid(&FT, grid_size, cell_size); //Делаем кастомное поле.
- sf::RenderWindow window(sf::VideoMode(grid_size.x*cell_size.x, grid_size.y*cell_size.y), "XO");
- sf::Sprite sprite_bg;
- sprite_bg.setTexture(FT.getTexture()); //Выне за вайл, смысла передергивать бэкграунд каждый раз нету.
- while (window.isOpen())
- {
- sf::Event event;
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- window.clear(sf::Color(192, 192, 192));
- window.draw(sprite_bg);
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement