Lordpun

Issue with SFML text drawing

Sep 24th, 2026
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. void drawActionMenu(sf::RenderWindow& window, std::vector<menuOption> options, int selectedIndex) {
  2. sf::RectangleShape menuBack = makeMenu({183.0f, 120.0f}, {45.0f, 315.0f});
  3. window.draw(menuBack);
  4.  
  5. sf::Font font("assets/fonts/pixelPirate.ttf");
  6. sf::Vector2f textStart = {50.0f, 320.0f};
  7. int fontSize = 10;
  8.  
  9. for (int i = 0; i < options.size(); i++) {
  10. sf::Text text(font);
  11. text.setCharacterSize(fontSize);
  12.  
  13. menuOption optionData = options.at(i);
  14. text.setString(" " + optionData.text);
  15. text.setPosition({textStart.x, textStart.y + i * fontSize});
  16.  
  17. if (i == selectedIndex) {
  18. text.setString("> " + optionData.text);
  19. text.setFillColor(sf::Color(240, 235, 86));
  20. }
  21.  
  22. if (!optionData.active) {
  23. text.setFillColor(sf::Color(158, 158, 158));
  24. }
  25.  
  26. window.draw(text);
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment