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.


Topics - TXRSTXN

Pages: [1]
1
General / Moving without using diagonal movement.
« on: February 18, 2016, 06:28:55 pm »
Hello!  :)
So basically I'm trying to make my character move without using diagonal movement. As for the basic structure of the movement it is going good. Now the problem is control the movement.

What I want is that when you for example press down, the character moves down. If you then press right, while still pressing down, the character moves right, and if you release right, the character goes back to moving down.

I've been trying to create this with several if's in all possible ways, but it doesn't work as it's supposed to.

Any ideas on how to make it work?

2
General / Timebased movement not working..
« on: February 07, 2016, 10:54:11 pm »
Okay, so I have been sitting for the last two days trying to work this out but it just wont work!

I am basically moving a circle relative to time. In this case I am  trying to make it move 100 px / second.
The problem is that the circle is moving really slow, and not 100 px / second at all. I have tried all kinds of ways to make it work but it's still not behaving as it's supposed to.

Can someone tell what I'm doing wrong?


int main() {
   
    sf::RenderWindow window(sf::VideoMode(700, 700), " ");
    sf::CircleShape circle(20);


    sf::Clock clock;        // Declaring clock, time and variable to measure the time.
    sf::Time time;
    double elapsed;


    while (window.isOpen()) {

        clock.restart();              // Restarting the clock.


        sf::Event event;
       
        while (window.pollEvent(event)){             // Event loop.
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }


        time = clock.getElapsedTime();        //Measuring time and moving the circle based on passed seconds.
        elapsed = time.asSeconds();
        circle.move(100*elapsed, 0);


        window.clear();
        window.draw(circle);
        window.display();
    }

    return 0;
}

 

Pages: [1]