• Create Account

### #Actualpinebanana

Posted 11 November 2012 - 01:12 AM

Two things:
I'm not sure if elapsed time is your delta time or if it's just a counter variable on how long the application has been running for
So have you tried doing this?

void Ball::MoveBall(float elapsedTime)
{
position_.x += xSpeed_;
position_.y += ySpeed_;
}


And what's the point of the speed variable? Also you should at least assign the speed variable in your constructor
Ball::Ball(sf::Vector2f position, float speed)
{
position_ = position;
speed_ = speed; // changed from 35.0f
xSpeed_ = -65.0f;
ySpeed_ = 65.0f;
}


You could use a sf::Vector2 to determine the direction of what the ball requires to go in (you should pre normalise it though) and your speed variable for the multiplier

i.e.
void Ball::MoveBall(float elapsedTime)
{
// where direction is a normalised vector
position_ += direction_ * speed_;
}


### #1pinebanana

Posted 11 November 2012 - 01:01 AM

Two things:
I'm not sure if elapsed time is your delta time or if it's just a counter variable on how long the application has been running for
So have you tried doing this?
void Ball::MoveBall(float elapsedTime)
{
position_.x += xSpeed_;
position_.y += ySpeed_;
}

And what's the point of the speed variable? Also you should at least assign the speed variable in your constructor
Ball::Ball(sf::Vector2f position, float speed)
{
position_ = position;
speed_ = speed; // changed from 35.0f
xSpeed_ = -65.0f;
ySpeed_ = 65.0f;
}

You could use a sf::Vector2 to determine the direction of what the ball requires to go in (you should pre normalise it though) and your speed variable for the multiplier

i.e.
void Ball::MoveBall(float elapsedTime)
{
// where direction is a normalised vector
position_ += direction_ * speed_;
}

PARTNERS