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

Pages: [1]
1
System / Finding Delta time in SFML 2.0
« on: February 19, 2012, 05:06:16 pm »
Thank you! Using AsSeconds did the trick. As for using a vector, I.. don't know why I'm not using them.  :)

2
Graphics / Animation doesn't loop
« on: February 19, 2012, 03:28:49 pm »
frameTime never changes, it just represents when to update the frame (in milliseconds). It is set when an asteroid object is instantiated.

Nexus, I will try the debugger and let you know. Also, thanks for the tip, I tend to write out more code than needed.

3
Graphics / Animation doesn't loop
« on: February 19, 2012, 06:25:13 am »
I just tried some variations of that but no luck. I also tried setting it to begin()+1 just to see if that made a difference, but it didn't. I'm convinced it has to do with the resetting of the iterator since it runs through the animation once perfectly fine.

4
System / Finding Delta time in SFML 2.0
« on: February 19, 2012, 12:31:11 am »
Thanks, I was making it more complicated than it needed to be. So am I right in assuming I would now do something like:

mySprite.Move( xVel * dT.AsMilliseconds(), yVel * dT.AsMilliseconds() ) ?

That's what I'm doing and although it's smoother it still jerks around a bit. Should I also be utilizing delta time when updating the display?

5
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())

6
Graphics / Animation doesn't loop
« on: February 18, 2012, 09:37:45 pm »
Using frames[index] gives me the same error. Logically the code makes sense to me so I'm really confused why it isn't working (unless my understanding of vector iterators is wrong...)

7
Graphics / Animation doesn't loop
« on: February 18, 2012, 01:01:38 am »
When it reaches max frames (there are 7 "frames" or sf::IntRects inside the "frames" vector) it is supposed to return to the first spot in the vector so the animation loops.

I tried setting frame = frames.front() but it spit out an error saying it wasn't a valid candidate.

8
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!

9
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]