1
SFML projects / Lagging in My Game
« on: April 09, 2020, 01:17:21 am »
Hello , i am a newbie, i have a college assignment to make a game. But i have problem , sometimes my game have a lagging. this is some sources code inside main looping (i suspect this is happening because sf::Time.
sorry my english is very bad:)
sorry my english is very bad:)
Quote
for(int i = 0; i < batas; i++)
{
if(k == i)
{
//Random jenis buah
randBuah = rand() % 3 + 1;
buah.Buah("image/pir.png","image/apel.png", "image/jambu.png", randBuah);
//Random posisi spawn buah
x = rand() % 1100 + 1;
buah.Set(x, y);
hitBuah.Set(x+30, y+50);
k++;
}
else continue;
}
//Draw buah dan memberikan kecepatan
detik = sf::seconds(1);
for(int i = 0; i < batas; i ++)
{
//memberikan delay setiap perulangan
//detik = sf::seconds(1);
if(waktu.getElapsedTime() >= detik && i >= batas-1)
{
hitBuah.Draw(window);
buah.Draw(window);
batas++;
waktu.restart();
}
else {
hitBuah.Draw(window);
buah.Draw(window);
buah.Move(0, 0.5);
hitBuah.Move(0, 0.5);
}
}