I'm trying to make a game in C++ similar to a visual novel, but I seem to be having a lot of trouble (this is my first game). I'm trying to make it so that whenever you hit enter a new sentence pops up. But whenever I hit enter, both pieces of text just flicker in front of each other. I also have a blue box that loads at the bottom of the screen. I've changed the text multiple times, and deleted the other string, but now the text won't load at all.
My other problem is that I think that if I keep developing the way I am, the whole game might just in the main.cpp file. I can't figure out a way to have the same objects over multiple files and because of that, all the text has to be written in the main file, so it can be displayed with App.Draw()
#include <SFML/Graphics.hpp>
int main(){
sf::RenderWindow App(sf::VideoMode(1024, 768), "Game");
//Loads the game font and images
sf::Font GameFont;
if (!GameFont.LoadFromFile("calist.ttf")) {
return EXIT_FAILURE;
}
sf::Image TextBoxImage;
sf::Sprite TextBox;
if (!TextBoxImage.LoadFromFile("Blue.png")) {
return EXIT_FAILURE;
}
TextBox.SetImage(TextBoxImage);
TextBox.SetColor(sf::Color(0, 0, 255, 155));
TextBox.SetPosition(0, 490.f);
TextBox.Scale(1.6f, 1.6f);
//Loads the game Text
sf::String dia1a ("That piece of trash over there is Joey.", GameFont);
//Game Loop
while (App.IsOpened())
{
App.Clear();
App.Draw(TextBox);
App.Display();
//Dialogue for level 1
sf::Event Dialogue1;
while (App.GetEvent(Dialogue1)) {
if ((Dialogue1.Type == sf::Event::KeyPressed) && (Dialogue1.Key.Code == sf::Key::Escape)) {
App.Draw(dia1a);
}
}
//Close Game
sf::Event GameClose;
while (App.GetEvent(GameClose)) {
if (GameClose.Type == sf::Event::Closed)
App.Close();
}
}
return EXIT_SUCCESS;
}
If anyone knows any solutions to displaying new text when the enter key is pressed, or using objects over multiple header files, please let me know. ^_^