So I am making a text adventure game with choices. The issue I have is that I made my text as an array list that goes on as you click to enter to advance the text, but every time you start the game, there is a blank screen until you click enter, and the prompt from the area starts.
When I manually put a text, I have it appearing at the start when you start the game. I tried placing it in other areas but won't go away when pressing enter. I notice if I have it in another class, it would o to the next class and continue, but it has that same issue where the screen will be blank until you click the enter button to show the next prompt.
How do I fix this issue?
Here is a copy of the code I have on my cpp file:
#include "Gameplay.h"
#include "GameText.h"
#include "ChoiceA.h"
Gameplay::Gameplay(std::shared_ptr<Context> &context) : context(context){}
Gameplay::~Gameplay(){}
void Gameplay::Init()
{
context->assets->AddFont(MainFont, "Assets/Myuniquefont-Regular.otf");
text.setFont(context->assets->GetFont(MainFont));
text.setOrigin(context->window->getSize().x/2.f,
context->window->getSize().y/2.f);
text.setPosition(context->window->getSize().x/2.f,
context->window->getSize().y/2.f);
text.setCharacterSize(65);
}
void Gameplay::ProcessInput()
{
std::string text_array[] = {"There was once a hafling and a dragon."
"\nThey were wandering around in secrecy.",
"Traveling together and far",
"And third text",
"option \"A\" or option \"B\""};
std::string text_array_two[] = {"We here on option A",
"Maybe here too?",
"unkown places but here we are"};
std::string text_array_twoSideB[] = {"We here on option B",
"Maybe here too? Or maybe not",
"unkown places but here we are"};
sf::Event event;
while (context->window->pollEvent(event))
{
text.setString("Please click enter to continue the story.");
if (event.type == sf::Event::Closed)
{
context->window->close();
}
if(event.type == sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::Return)
{
text.setString("Please click enter to continue the story.");
// text.setString(text_array[text_counter]);
// text_counter++;
}
else if(text_array->back() && event.key.code == sf::Keyboard::A)
{
// context->states->Add(std::make_unique<ChoiceA>(context), true);
// text_counter = 0;
}
// else if(text_array->size() -1 && event.key.code == sf::Keyboard::B)
// {
// text.setString(text_array_twoSideB[text_counter_two]);
// text_counter_two++;
//
// }
}
}
}
void Gameplay::Update(sf::Time deltaTime)
{
}
void Gameplay::Draw()
{
context->window->clear();
context->window->draw(text);
context->window->display();
}
and here is my header file:
#ifndef SFML_PROJECT_GAMEPLAY_H
#define SFML_PROJECT_GAMEPLAY_H
#pragma once
#include "State.h"
#include "Game.h"
#include "GameText.h"
#include <memory>
#include <SFML/Graphics.hpp>
class Gameplay : public Engine::State
{
private:
std::shared_ptr<Context> context;
sf::Text text;
public:
Gameplay(std::shared_ptr<Context>& context);
~Gameplay();
unsigned int text_counter = 0;
unsigned int text_counter_two = 0;
void Init() override;
void ProcessInput() override;
void Update(sf::Time deltaTime) override;
void Draw() override;
void Pause() override;
void Start() override;
};
#endif //SFML_PROJECT_GAMEPLAY_H
As you can see, I tried different ways to clear the blank spot, but I keep running a road block with a manual string that won't clear no matter if I tried to destroy it or clear it off the screen.