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

Author Topic: draw on different levels  (Read 1267 times)

0 Members and 1 Guest are viewing this topic.


  • Guest
draw on different levels
« on: November 22, 2019, 05:05:32 pm »
Hello everybody.
I need some tips.
I have my vector of animated tiles all drawn in a tile map, i have a view that moves and show what i need if i navigate in the map or i zoom. And here everything is okay.
Now i need to implement an interaction UI that will appear once i click on a tile and that if i close the ui (from itself) it will disappear. This UI will have it's origin in the center of the tile i clicked and it must be anchored there.
My problem is that i can't figure out how to handle this. I could draw it as a simple sprite but i thought that the animation, which move a rect in the sprite sheet and set the new texture and then draw again every tile, would make some problems so i would like to learn how to handle views or at least to draw on different levels.
I need the UI to don't zoom with the view that shows the map, but i need it to move with the map, as if it is anchored.
I was thinking about a second view that only shows this menu (with will be a sprite made of a texture, some texts and IntRect... so maybe i should make a RenderTexture and than pass it to a sprite and draw it?) but i don't know how to draw objects in a view (neither if it is somehow possible to have an effect like this). I really can't understand how to do this.
I was also looking at the viewPort since i was thinking of using it for a main GUI with will be always displayed in the top of the screen, so maybe i could use this to create a kind of minimap (just to make you know my idea) in a precise position every time i have to open a ui menu on the tile.
I Don't really know, i really need help.

thanks everybody that will help me, sorry if this is something stupid to your hear, but i am learning by my own and i am still a bit newbie.
« Last Edit: November 22, 2019, 05:17:04 pm by koyuki »


  • SFML Team
  • Hero Member
  • *****
  • Posts: 9573
    • View Profile
    • development blog
    • Email
Re: draw on different levels
« Reply #1 on: November 26, 2019, 08:52:30 pm »
You really just want two views.

Set the first view, then render your game world objects.
Then set the second view and render your GUI.

The GUI view should not be modified, except to account for window resizes, and thus your GUI will always remain stationary.
While at the same time, you can move around your game world view, follow the player, zoom in on the action, etc. all while the GUI stays stationary.

See also the official view tutorial or my own view tutorial from a while back.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/