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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - itsZ3r0x

Pages: [1]
1
General / Re: Dialogue-Box | Game-Developement with SFML
« on: February 23, 2017, 10:35:05 pm »
Thanks for your help, Arcade!  ;).

Now I got another way for the updateText function (your answer brought me to this idea).

Here is the full textbox-class for all who are interested in:


#pragma once
#include <SFML\Graphics.hpp>
#include <iostream>

using namespace sf;

class MessageBox {

public:

        MessageBox()
        {
                t_messageBox.loadFromFile("assets/message_boxes/message_box.png");
                s_messageBox.setTexture(t_messageBox);
                Pixel.loadFromFile("assets/message_boxes/Pixel.ttf");
                MessageBox_text.setFont(Pixel);
        }

        void setText(String text, int x, int y, int size)
        {
                MessageBox_text.setFillColor(Color::White);
                MessageBox_text.setPosition(x, y);
                MessageBox_text.setString(text);
                MessageBox_text.setCharacterSize(size);
        }
       
        void drawMessageBox(RenderWindow &window)
        {
                if (visible == true)
                {
                        window.draw(s_messageBox);
                        window.draw(MessageBox_text);
                }
        }


        void updateText(String UpdateText, String UpdateText2, String UpdateText3, Event &event)
        {
       
                if (event.type == event.KeyReleased)
                {
                        if (event.key.code == Keyboard::Space)
                        {
                                if(currentText <= 2) currentText++;
                                else {
                                        visible = false; //hides the textbox
                                }
                        }
                }

                switch (currentText)
                {
                case 0: MessageBox_text.setString(UpdateText); break;
                case 1: MessageBox_text.setString(UpdateText2); break;
                case 2: MessageBox_text.setString(UpdateText3); break;
                }

        }


private:
        Texture t_messageBox;
        Sprite  s_messageBox;
        Font Pixel;
        Text MessageBox_text;

        bool visible = true;

        int currentText = 0;
};

 

Arcade, thanks for your help! ;D

2
General / Re: Dialogue-Box | Game-Developement with SFML
« on: February 23, 2017, 06:14:11 pm »
Here is my edited code:

void updateText(String UpdateText, int x, int y, int size, String UpdateText2, int x2, int y2, int size2)
        {
                Clock clock1;
                Time tempClock1;
                Time elapsed1 = clock1.restart();
                tempClock1 += elapsed1;

                if (tempClock1.asSeconds() > 4)
                {
                        if (Keyboard::isKeyPressed(Keyboard::Space))
                        {
                                MessageBox_text.setString(UpdateText);
                                MessageBox_text.setPosition(x, y);
                                MessageBox_text.setCharacterSize(size);

                                Clock clock2;
                                Time tempClock2;
                                Time elapsed2 = clock2.restart();
                                tempClock2 += elapsed2;

                                if (tempClock2.asSeconds() > 4)
                                {
                                        if (Keyboard::isKeyPressed(Keyboard::Space))
                                        {
                                                MessageBox_text.setString(UpdateText2);
                                                MessageBox_text.setPosition(x2, y2);
                                                MessageBox_text.setCharacterSize(size2);
                                        }
                                }
                        }
                }
        }
 

But when I press spacebar, nothing happens  :-\.

3
General / Re: Dialogue-Box | Game-Developement with SFML
« on: February 23, 2017, 06:07:20 pm »
So I have to create the clock inside the updateText function?

4
General / Re: Dialogue-Box | Game-Developement with SFML
« on: February 23, 2017, 05:16:15 pm »
But I start clock 2 if clock1 is greater than 4s. So that means: When clock1 is not greater than 4 seconds, clock 2 is at 0 second. Or have I got that wrong?

5
General / Dialogue-Box | Game-Developement with SFML
« on: February 23, 2017, 04:29:59 pm »
Hello,

I have a problem. I am trying to write a function that creates a Dialogue Box for my Game. When the time is bigger than 4s, the player should be able to press the Spacebar and a new Text appears. But when I press the spacebar, the second updateText appears. What I´m doing wrong? I call the function in the main Game Loop.
I´m a beginner in creating Games with SFML - so don´t be to strict with me  ;).

Here is my code:




void updateText(String UpdateText, int x, int y, int size, String UpdateText2, int x2, int y2, int size2)
        {
                Time elapsed1 = clock1.restart();
                tempClock1 += elapsed1;
               
                if (tempClock1.asSeconds() > 4)
                {
                        if (Keyboard::isKeyPressed(Keyboard::Space))
                        {
                                MessageBox_text.setString(UpdateText);
                                MessageBox_text.setPosition(x, y);
                                MessageBox_text.setCharacterSize(size);

                                Time elapsed2 = clock2.restart();
                                tempClock2 += elapsed2;

                                if (tempClock2.asSeconds() > 4)
                                {
                                        if (Keyboard::isKeyPressed(Keyboard::Space))
                                        {
                                                MessageBox_text.setString(UpdateText2);
                                                MessageBox_text.setPosition(x2, y2);
                                                MessageBox_text.setCharacterSize(size2);
                                        }
                                }
                        }
                }
        }

 

Pages: [1]
anything