1
Graphics / How can i slow down the rate my projectiles fire.
« on: April 23, 2017, 11:20:52 pm »
I have a function that draws and moves a projectile automatically based on if a certian monsters are in range or not. The problem I am having is that when the monsters in range it draws it so many times its almost like a line. I have been at this for so many hours im about to throw in the towel. I have tried using the clock but its just not working out.
This function checks if the monster is in range and pushes back a vector of bullets.
This function draws it to the window. But it draw it so many times its ridiculous
Any help would be great.
This function checks if the monster is in range and pushes back a vector of bullets.
for (int i = 0; i < mymonsters.size(); i++)
{
for (int k = 0; k < myicetower.size(); k++)
{
if (mymonsters[i].checkCollision(myicetower[k].getRadius(), myicetower[k].getPositionX(), myicetower[k].getPositionY()))
{
// BulletClass bulletshot;
bulletshot.setPosition(myicetower[k].getPositionX(), myicetower[k].getPositionY());
bullet.push_back(bulletshot);
}
}
}
{
for (int k = 0; k < myicetower.size(); k++)
{
if (mymonsters[i].checkCollision(myicetower[k].getRadius(), myicetower[k].getPositionX(), myicetower[k].getPositionY()))
{
// BulletClass bulletshot;
bulletshot.setPosition(myicetower[k].getPositionX(), myicetower[k].getPositionY());
bullet.push_back(bulletshot);
}
}
}
This function draws it to the window. But it draw it so many times its ridiculous
sf::Vector2f fire(1.f, 1.f);
for (int i = 0; i < bullet.size(); i++)
{
//if(function.checkCollision(myicetower, mymonsters))
{
bullet[i].fire(fire);
bullet[i].draw(window);
}
}
window.display();
}
for (int i = 0; i < bullet.size(); i++)
{
//if(function.checkCollision(myicetower, mymonsters))
{
bullet[i].fire(fire);
bullet[i].draw(window);
}
}
window.display();
}
Any help would be great.