SFML community forums

General => SFML projects => Topic started by: bakar12344 on April 09, 2020, 01:17:21 am

Title: Lagging in My Game
Post by: bakar12344 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:)

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);
            }
        }
Title: Re: Lagging in My Game
Post by: eXpl0it3r on April 09, 2020, 09:12:44 pm
If it's an assignment, then I highly recommend to ask your teacher/assistant as they are being paid to help you, plus they know exactly what you should be doing. ;)

With the given code and the very generic description "lagging" we can't really help you further.
Create a minimal and compilable example that reproduces the issue, that way we see the full code and can reproduce it locally and with any luck, you'll figure out the issue on your own, when reducing the code.