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 - Bobson

Pages: [1]
1
General / Changing screen when player is outside window.
« on: March 26, 2014, 07:09:42 pm »
I am creating my first game (for learning purposes) and its based on text commands. If i for example tell my player to move to the right screen i want him to move until he reaches the border of the screen and then switch to the next screen. See images for example.

http://imgur.com/RHBisbz
then i enter move right
http://imgur.com/Yd3dhcO

Right now the screen switches instantaneously as i type the command. I am trying to make a move function where i want him to move to the right and when he reaches the end the window the screen will switch. My question right now is how can i make him move to a vector (x,y) position over a certain time? I know i can change his position with mPlayer.setPosition(sf::vector2f) but then he will move instant and not over a certain time.

I have tested some with this code:

void Game::update(sf::Time deltaTime)
{
if (GoUp)
        {
                Spelare.mPlayer.setPosition(sf::Vector2f((Spelare.mPlayer.getPosition().x),(Spelare.mPlayer.getPosition().y-0.3)));
                Spelare.source.y = Spelare.Up;
        }

        if (GoDown)
        {
                Spelare.mPlayer.setPosition(sf::Vector2f((Spelare.mPlayer.getPosition().x),(Spelare.mPlayer.getPosition().y+0.3)));
                Spelare.source.y = Spelare.Down;
        }

        if (GoLeft)
        {
                Spelare.mPlayer.setPosition(sf::Vector2f((Spelare.mPlayer.getPosition().x-0.8),(Spelare.mPlayer.getPosition().y)));
                Spelare.source.y = Spelare.Left;
        }

        if (GoRight)
        {
                Spelare.mPlayer.setPosition(sf::Vector2f((Spelare.mPlayer.getPosition().x+0.8),(Spelare.mPlayer.getPosition().y)));
                Spelare.source.y = Spelare.Right;
        }
}

This is 4 different booleans for each direction so if i want him to move to a location i can set for example goUp and GoLeft to true but he will never stop and the code is ugly.

2
General / Re: Appending and writing a sf::string to a file.
« on: March 26, 2014, 04:12:49 pm »
Works as intended now, The issue didnt have anything to do with sfml , I didnt append the string properly in the function i used and it didnt write anything to my file.

 

3
General / Appending and writing a sf::string to a file.
« on: March 26, 2014, 03:41:08 pm »
Hello, I am trying to append a sf::string by adding text of type sf::Text. Then i want to write this file with a ofstream to a textfile. What i need this for is to save the history from the text input in my game.

Example Code):

sf::String string1 = "";
sf::Text text1("Input:  ", somefont, somesize);
sf::Text text2("Go north ", somefont, somesize);
sf::Text text3("Going north!", somefont, somesize);

string1 += text1.getString();
string1 += text2.getString();
string1 += text3.getString();

std::ofstream myfile;
myfile.open ("History.txt");
myfile << string1; //Error here, cant add a sf::string
myfile.close();
 

I have tried casting the sf::string after the appending to a std::string like this:
std::string temp = string1;
but that doesent work either. whats the correct way of doing a appending and filewriting with a sf::string?
Would love to see some code examples aswell since im quite new to Sfml!

Pages: [1]