Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Lagging in My Game  (Read 2202 times)

0 Members and 1 Guest are viewing this topic.

bakar12344

  • Newbie
  • *
  • Posts: 2
    • View Profile
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:)

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);
            }
        }

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Lagging in My Game
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/