I copied the
unsigned int text_counter = 0;
std::string text_array[] = {"This is the first text",
"This is the second one",
"And third text",
"End"};
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return)
{
if (text_counter < (sizeof(text_array) / sizeof(text_array[0])))
{
text.setString(text_array[text_counter]);
text_counter++;
}
}
Parts into mine and yeah only the first part of the array appears only. I even put the array in the same class function I have for the event to see if that was the issue but was not.
GamePlay::GamePlay(std::shared_ptr<Context> &context) : context(context),
AdvanceButton(false)
{
}
GamePlay::~GamePlay()
{
}
void GamePlay::Init()
{
//rectangle shape of the chat box
chatBox.setSize({1500, 320});
chatBox.setFillColor(sf::Color::Black);
chatBox.setOutlineColor(sf::Color::White);
chatBox.setOutlineThickness(5.f);
chatBox.setOrigin(chatBox.getGlobalBounds().width/1,
chatBox.getGlobalBounds().height/1);
chatBox.setPosition(context->window->getSize().x/1.1f,
context->window->getSize().y/1.01f);
//Titlle screen name of the game code
context -> assets ->AddFont(MainFont, "Assets/Asdonuts.ttf");
text.setFont(context->assets->GetFont(MainFont));
text.setCharacterSize(50);
text.setFillColor(sf::Color::White);
text.setPosition(context->window->getSize().x/5.7f,
context->window->getSize().y/2);
}
void GamePlay::ProcessInput()
{
unsigned int text_counter = 0;
std::string text_array[] = {"This is the first text",
"This is the second one",
"And third text",
"End"};
sf::Event event;
while(context->window->pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
context->window->close();
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return)
{
if (text_counter < (sizeof(text_array) / sizeof(text_array[0])))
{
text.setString(text_array[text_counter]);
text_counter++;
}
}
}
}
void GamePlay::Update(sf::Time deltaTime)
{
// text.setString("Hello There");
//
// text.setString("Hello Again");
}
void GamePlay::Draw()
{
context->window->clear(sf::Color::Black);
context->window->draw(chatBox);
context->window->draw(text);
context->window->display();
}