Skip to content

Latest commit

 

History

History
18 lines (14 loc) · 1.46 KB

File metadata and controls

18 lines (14 loc) · 1.46 KB

SFML_GUI

1. Data Structure (Backend)

Most developers use standard C++ containers to store item data. With SFML 3 moving to C++17, you have access to modern tools for this:

  • std::vector: The most common choice for a simple list of items.
  • std::unordered_map: Ideal for an Entity Manager where you need to retrieve items by ID or name.
  • Custom Class: Create an Item class to hold properties like name, weight, and a pointer to an sf::Texture.

2. Rendering (Frontend)

SFML 3 introduced several changes to how you display graphics:

  • Grid Layout: Use a loop to draw a series of sf::RectangleShape objects to create slot backgrounds, then draw sf::Sprite icons on top of them.
  • Scoped Enums: If you use enums for item types (e.g., Weapon, Potion), remember that SFML 3 uses scoped enumerations. For example, your code would look like ItemType::Weapon instead of just Weapon.
  • Scissor Testing: You can now use sf::View's scissor testing to ensure inventory items stay within the UI panel and don't "bleed" into the main game area.

3. Interaction

  • Event Handling: Use the new sf::Event::getIf syntax in SFML 3 to check for mouse clicks on inventory slots.
  • UI Libraries: Instead of building from scratch, you can integrate imgui-sfml, which supports SFML 3 and provides ready-made window and button widgets. HOWEVER - You will have build these by yourself and deeply integrate with your project that mileage will greatly vary