I have a code where the camera scroll left, right, up, down, and I would like to add a progress bar similar to the one below at the bottom of my window

enter image description here

Is it possible to create the progress bar in a different window and then join my top game window with this new window, so they can render at different times? If not (by using only one window) when scrolling up and down I would have that progress bar in the way, indeed my camera is set to the exact dimension of window height and window width and currently works flawlessly without that bar because the bar is not part of my current texture.

Any suggestion how to join two windows in one? I have created the bottom_Window so far (so I can try to develop the progress bar) but I want it to be fully merged with the top one (the actual game) so they can be moved at the same time)

Many thanks!

  • \$\begingroup\$ I assume that your background and the other game objects are being offset by your camera, so that whenever the camera is moving to the right, everything else moves to the left, giving the illusion of a scrolling game world. When it comes to the progress bar at the bottom of the window, can't you just offset the game objects like you currently do and leave the HUD text static (so not affected by the camera) making it a static HUD that is always present in the window? \$\endgroup\$ – Daniel_1985 Dec 2 '20 at 2:21
  • \$\begingroup\$ You were right, thank you very much for your tips! \$\endgroup\$ – The Thinker Dec 3 '20 at 1:59

The X, Y positions of Player and Backgrounds were rendered relative to the camera:


const SDL_Rect PlayerQuad = {(int)(Player.XPosition - Camera.XPosition), (int)(Player.YPosition - Camera.YPosition), (int)Player.Width, (int)Player.Height};

SDL_RenderCopy(pRenderer, Player.playerTexturewr, nullptr, &PlayerQuad);

The X, Y positions of the progressing bar had to be rendered NON RELATIVE TO THE CAMERA):

const SDL_Rect BarQuad = {(int)Bar.XPosition, (int)Bar.YPosition, (int)Bar.Width, (int)Bar.Height}; SDL_RenderFillRect(pRenderer, &BarQuad);

  • \$\begingroup\$ I just want to note that SDL nowadays contain float versions of objects and functions (SDL_RectF, SDL_RenderFillRectF, SDL_RenderCopyF etc), which accepts float values instead of integers. This means no typecasts need to be made and also opens up the opportunity of rendering on sub-pixel positions. \$\endgroup\$ – Daniel_1985 Dec 4 '20 at 15:58
  • \$\begingroup\$ Also don't forget to mark this answer as the correct one, if it helped you solve the problem. \$\endgroup\$ – Daniel_1985 Dec 4 '20 at 16:00
  • \$\begingroup\$ Thanks, I’ll be happy to mark your comment as well but looks like I can mark only answers \$\endgroup\$ – The Thinker Dec 7 '20 at 23:43
  • \$\begingroup\$ Don't worry about comments containing the correct answer or not, it's only posted answers that can be marked as the correct one. :) \$\endgroup\$ – Daniel_1985 Dec 8 '20 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.