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

Pages: [1]
1
Graphics / Re: Using sf::Clock on a moving ball.
« on: April 30, 2014, 03:19:27 am »
Embarrassing, not sure how I managed that. In any case, I get some very strange behavior regarding the position of the sprite. It doesn't seem to move pixel by pixel from where I want it to, it appears higher up into the program.

It multiplies the amount of pixels it will move based on the amount of time spent, so my sprites get shot to the edges of the corner. At a lower framefrate cap, they reach outside of the window's view.

2
Graphics / Re: Using sf::Clock on a moving ball.
« on: April 30, 2014, 01:59:00 am »
The really simple and probably good enough solution:

//code example

Taken from the (unfortunately very easy to miss) SFML FAQ.

Appreciated, but I may still require some help.

If I'm not mistaken
sprite.move( speed * delta, 0.f );

speed * delta replaces my move 1 pixel? I'm having a hard time understanding it.

I have tried this solution before to no success, is it because of how I'm controlling how many pixels it will move with a for loop? The sprite is simply stationary when using this code:
                        for (int i = 0; i < 90; i++) // Goes right 1 pixel 90 times
                        {
                                float delta = clock.restart().asSeconds();
                                // Move token 1 pixel to right
                                pOneSprite.move(sf::Vector2f(speed * delta, 0.0f));

                                // Redraw frame
                                window.draw(boardSprite);
                                window.draw(pOneSprite);
                                window.display();
                                window.clear();
                        }

I assume I'm putting something in the wrong place?

3
Graphics / Re: Using sf::Clock on a moving ball.
« on: April 30, 2014, 12:38:05 am »
Basically you have to take the time between frames into account when you update/draw your objects.

Here are some really good articles on the subject that I suggest you read:

http://gafferongames.com/game-physics/fix-your-timestep/
http://www.koonsolo.com/news/dewitters-gameloop/
http://gameprogrammingpatterns.com/game-loop.html

I see these posted a lot but I'm not entirely sure how I can incorporate them into how I draw objects.

                                for (int i = 0; i < 90; i++)
                                {
                    pOneSprite.move(sf::Vector2f(-1, 0));

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

This basically moves and redraws pOneSprite by 1 pixel every loop iteration. How could I incorporate a "timestep" into something like this? I have the framerate set to 60 and I would like the visual speed to remain the same on a slower system.


Pages: [1]
anything