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

Pages: [1]
1
System / Finding Delta time in SFML 2.0
« on: February 18, 2012, 09:52:10 pm »
I'm still new to game programming, so please forgive me if I'm asking a stupid question. I can't seem to wrap my head around how to find the time between frames (delta time) in SFML 2.0. I understand 1.6 had "GetFrameTime()" but that it is now removed.

I'm trying to get smoother player movement by multiplying velocity by delta time, but I need to figure out delta time first. Does anyone have an easy example for this?

I tried creating a function to calculate the delta time (runs once every screen render):

Code: [Select]

    sf::Time currentTime;
    //get current elapsed time of frame
    currentTime = deltaClock.GetElapsedTime();

    deltaTime = ( currentTime - prevDeltaTime );

    prevDeltaTime = currentTime;
    deltaClock.Restart();


And then multiplying player velocity by the variable "deltaTime" (which is of type sf::Time) but it either doesn't move the player at all or at very small/random intervals (if i multiply by deltaTime.AsMilliseconds())

2
Graphics / Animation doesn't loop
« on: February 17, 2012, 11:52:26 pm »
Not sure if this belongs here, but, here is my issue: my little animation function doesn't loop. I have a class for "asteroids" and this member function animates a spinning motion (no user input required, happens every render cycle). Here is my code ("frames" is a vector array and "frame" is an iterator):

Code: [Select]

void Asteroid::animate()
{
    if ( frame == frames.end() ) frame = frames.begin();
    //if frame time has elapsed, move to next frame in animation
    if ( frameClock.GetElapsedTime().AsMilliseconds() >= frameTime.AsMilliseconds() )
    {
        mySprite.SetTextureRect(*frame); //set frame
        ++frame;
        //reset clock
        frameClock.Restart();
    }
}


The code does partially work, as it loops through the 7 frames once. However, after that the asteroid simply disappears (as if the 'frame = frames.begin()' isn't working). Any help is appreciated!

3
Graphics / Need Help with simple bouncing collison/math
« on: February 02, 2012, 10:28:35 pm »
I feel like I'm going to make this highly convoluted so please bear with me. I'm in the process of teaching myself C++ and SFML(2.0) and am making a relatively simple game. I have multiple rocks bouncing around the screen that I want to bounce off of each other.

Right now I have them bouncing off the edges of the screen fine, and off each other when colliding along the x axis. This is really an issue of math I think (and my main problem is my math skills are very lacking). I have, in the collision detection code, the rock's angle changing using the formula: angle = Pi - angle (which works when bouncing off the left and right sides of the screen). However, my code for bouncing off the top and bottom of the screen simply inverts the angle (angle = -angle).

I know using "angle = -angle" will work for y axis rock-to-rock collisions, so I guess my question is, how do I check (once they have collided) whether to use "angle = -angle" or "angle = Pi - angle"?

Pages: [1]