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

Pages: [1]
1
General / Re: Frames at the time
« on: September 11, 2014, 10:28:09 am »
Thank you Laurent and FRex, i fixed timestep in my game, and now it works exactly how i wanted. The same speed with different frame rates, clear code, no bugs like objects falling through the floor or disappearing when i move the window, also clear physics, no matter if the frame rate is 5 or 500 FPS. Here's the source code of my game object:

Game::Game(void)
: window(sf::VideoMode(window_size_x, window_size_y), "Ambient"),
view(sf::FloatRect(0, 0, float(window_size_x), float(window_size_y))),
updateFPS(1000),
dt(1.0f / updateFPS),
elapsedTime(0.0f),
accumulator(0.0f),
currentTime(clock.getElapsedTime().asMilliseconds())
{
        init();
}
 

And game run() function:

void Game::run()
{
        while (window.isOpen())
        {
                /* Events */
                EventHandling();

                /* Timestep */
                newTime = clock.getElapsedTime().asMilliseconds();
                frameTime = static_cast<float> (newTime - currentTime) / 1000.0f;
                if (frameTime > 0.25f) frameTime = 0.25f;
                currentTime = newTime;
                accumulator += frameTime;
                while (accumulator >= dt)
                {
                        elapsedTime += dt;
                        accumulator -= dt;
                        /* Game Logic Update */
                        GameLogicUpdate();
                }

                /* View */
                View();

                /* Draw */
                Draw();
        }
}

Problem solved.

2
General / Frames at the time
« on: September 04, 2014, 10:08:55 am »
Hello, i've been working on a game project recently, and i already implemented some stuff, i have collisions, entities, bullets, movable camera. But after all this, i am still wondering about how to handle frames per second. Right now my code works on a simple principle, it measures the time of each frame and move the objects with constant speed multiplayed by that time:

float delta = clock.restart().asSeconds();
...
hero.sprite.move(hero.h_speed * delta, hero.gravity_delta * delta);

Works? Works. But looks a little poor, becouse i have to keep an eye on every single movement instruction and i'm pretty sure it could be done better. I've already tried the "update()" method which updates all the game logic by a constant time, but i don't like it, becouse i have to set the FPS limit then, and if the PC isn't good enough to handle it, the game works slower. How do all of these big games do it? I'd like to implement a method which will let me to keep the game logic in one separate function, but also does not force me to set the constant FPS and works with exact same speed on every computer, no matter if it's 15 or 150 FPS.

3
Graphics / Re: Bounding box collision problem
« on: July 31, 2014, 01:53:39 pm »
Thanks for the advices, i modified the code a little bit. Now it looks less nebwie :D But still don't know how to implement proper moving during collision. It's good only for the floor, but maybe it's enough. I think i would just have to avoid building map with few separated objects in one wall. Here's the code after changes:
(click to show/hide)

4
Graphics / Re: Bounding box collision problem
« on: July 30, 2014, 10:18:29 pm »
Yeah, i have to learn much more, thanks for the cointainers, very helpful.

5
Graphics / Re: Bounding box collision problem
« on: July 30, 2014, 09:01:25 pm »
Well, now i'm kinda confused. I added the colors to box collision function, but it changes the color for only one sprite at the time. Even if i collide with two sprites at the same time, one of them is red, other default (only in corners it sets two sprites red). So maybe my dollision detection itn't working properly.
Here's the example of how it looks: http://scr.hu/2d0y/c6l0u
In 1 and 2 i'm pressing left/right arrows, in 3 up and right.

6
Graphics / Bounding box collision problem
« on: July 30, 2014, 09:33:16 am »
Hi, im working on a project (2D platformer game), and i'm trying to achieve proper collisions on my map. The problem is, i want my collisions to be perfect (work in every possible situation). I wrote a function which meets my expectations almost perfectly, but there is a problem with corners. When i'm trying to move in two directions at once, up and right for example, and my character meets the box corner, it stops and i can't go further until i release one of the buttons to specify the one exact direction. It only happens when im moving counter clockwise (pressing two butons, like up+right, up+left, left+down). Here's the code to visualize the problem:
(click to show/hide)
"triangle" sprite has rectangular 100x100 texture, "box" sprites also.

Pages: [1]
anything