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

Author Topic: Help with Clearing the Window  (Read 5264 times)

0 Members and 1 Guest are viewing this topic.

wiired24

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Help with Clearing the Window
« on: November 09, 2016, 02:57:44 am »
First i would like to say hello. I'm rather new to SFML and somewhat new to C++ as well. I'm glad to be in a community of indie developers. I've been looking over alot of peoples projects and many of them i find to be inspiring to say the very least.

I'm working on build a small 2D RPG. It's going to be very minimal just a title screen, an overworld map, maybe a few npcs and if i can figure out how to implement AI, a battle system. This is my first SFML C++ project so i think it would be foolish to try and make the next Diablo or Final Fantasy off the bat. Here is a screenshot of the game currently titled "Dungeons & Monsters"(Original I know right :P).


The Problem i'm having is after the window opens and the user sees the title screen  i'm trying to implement some logic to where when the user presses the Return key the screen will then clear and everything i drew initially for the title screen  will be cleared. Then  i could draw to a new frame basically.  I can't figure out exactly how to implement this. I've tested the input from the return key on keyboard and it is working correctly.  If anyone could offer some input or suggestions how to implement this that would be great. Thanks in advance guys.  I have attached the source as well feel free to look it over.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
AW: Help with Clearing the Window
« Reply #1 on: November 09, 2016, 09:49:37 am »
To clear the screen you call window.clear(). ;)

What you don't want to do is just drawing one frame and the "pause", you should really just keep rendering 30-60 frames a second.

As for your problem, it sounds a bit like you might want to apply the state pattern to your game. That way you have the state "menu" and then you switch and have the state "game", etc.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

wiired24

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Help with Clearing the Window
« Reply #2 on: November 10, 2016, 02:36:50 am »
Thanks for the imformative response. I managed to get the window.clear() function  to work but the only problem is after passing in sf::color::white as a parameter rather than clearing the screen to the color white and staying white it just flickers with the color white really fast.   I don't understand why it's doing this.

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Help with Clearing the Window
« Reply #3 on: November 10, 2016, 03:27:50 am »

This is because everithing that draws the windows modify what you see.

if you call
window.clear( sf::Color::White )

Any calls of those types
 window.clear( anyColorDifferentOfWhite )
and
 window.draw()
will change what the screen is drawing.

If you want to keep the color to white you'll need to ensure that only you have those types of calls
window.clear( sf::Color::White )
before
 window.display() ;
I would like a spanish/latin community...
Problems building for Android? Look here

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Help with Clearing the Window
« Reply #4 on: November 10, 2016, 06:37:27 am »
http://www.sfml-dev.org/tutorials/2.4/graphics-draw.php#the-drawing-window

Please read this paragraph carefully, especially the big red box at the end.
Laurent Gomila - SFML developer

 

anything