Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML adding a menu bar to my project  (Read 3717 times)

0 Members and 1 Guest are viewing this topic.

physicskush

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML adding a menu bar to my project
« on: January 16, 2022, 12:30:56 am »
Hello people, I developed a chess game using SFML and now I'm stuck on trying to add a menu bar at the top (with buttons). I am asking you guys for help on how should I approach this problem.

From my understanding, I need an extra panel on top of my preexisting window, wherein I will add the buttons under a certain layout. So maybe extend the height of my window, and draw my chess board with a vertical offset downwards? But then, in my chess game I use the
event.mouseButton.y
coordinates all the time so will I have to subtract the height offset? That seems like an incorrect approach.

What is a good approach to this problem, can anyone guide me? I used
RenderWindow window(VideoMode(640,640), "Chess Game", style::Titlebar | Style::Close)
to generate my window object.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML adding a menu bar to my project
« Reply #1 on: January 16, 2022, 11:52:10 am »
From my understanding, I need an extra panel on top of my preexisting window, wherein I will add the buttons under a certain layout. So maybe extend the height of my window, and draw my chess board with a vertical offset downwards?
Yes, that's one option. Another would be to keep drawing the board from Y=0 downwards, and set up a sf::View which begins at negative Y.

But then, in my chess game I use the
event.mouseButton.y
coordinates all the time so will I have to subtract the height offset? That seems like an incorrect approach.
In general, you should differentiate between "viewport coordinates" (like mouse) and "world coordinates" (your chess board). Always translate from one to the other via mapPixelToCoords(), don't just static_cast. Then, it's also very easy to add custom logic in just one place instead of dozens.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: