Hello all,
I have been working on a small 2d rpg game, i am at the point where i need to use my game timer but it seems there is a problem with it and i can not figure out what it is. i have a fire ball that gets spawned and moves in a certain direction and continues untill outside of screen.
void FireBall::FireBall()
{
//set movement
switch (Direction)
{
case AD_Up:
Acceleration.Y -= speed; // speed = 0.05
break;
case AD_Down:
Acceleration.Y += speed;
break;
case AD_Left:
Acceleration.X -= speed;
break;
case AD_Right:
Acceleration.X += speed;
break;
}
}
void FireBall::Update()
{
double dt = ThePrecisionDeltaTime::Instance().GetDt();
Velocity += Acceleration * dt;
Acceleration = 0;
Location += Velocity * dt;
}
void FireBall::Draw(Camera* camera)
{
Vector2F camtrans = Location - Vector2F(camera->Screen.Location());
mFireBallSheet->Draw(animation.GetAnimationFrame(), camtrans);
}
and my timer:
Windows_PrecisionDeltaTime::Windows_PrecisionDeltaTime()
{
LARGE_INTEGER Frequency;
QueryPerformanceFrequency(&Frequency);
m_Frequency = double(Frequency.QuadPart) / 1000.0;
}
double Windows_PrecisionDeltaTime::GetTicks() const
{
return m_CurrentTick;
}
double Windows_PrecisionDeltaTime::GetDt() const
{
return m_DeltaTime;
}
void Windows_PrecisionDeltaTime::Update()
{
LARGE_INTEGER CurrentTick;
QueryPerformanceCounter(&CurrentTick);
m_CurrentTick = double(CurrentTick.QuadPart) / m_Frequency;
m_DeltaTime = m_CurrentTick - m_LastTick;
m_LastTick = m_CurrentTick;
}
The problem is when i play the game in release or debug the fireball will fly at different speeds, also in release if i shoot them in close proximity some fireballs go faster than other fireballs when the speed should be a constant.
do any of you know what i am doing wrong here. i can record a vid if that will help illustratie the problem more.