0
\$\begingroup\$

I am trying to build a game in pygame, however any movement feels laggy. Its not a big lag but more like a small stuttering.

I created a boiled down version to showcase this. The code in the git below does nothing but create a red ball that moves over your display. Despite its simplicity, the lag still remains.

https://github.com/Ogorf/Spong

Thanks in advance to anyone taking the time!

EDIT: I run the main with:

$ python -m Spong.main

from the Spong folder

\$\endgroup\$
13
  • \$\begingroup\$ Does this answer the question? stackoverflow.com/a/61012560 \$\endgroup\$
    – user163857
    Jul 23, 2022 at 16:23
  • 1
    \$\begingroup\$ This code doesn't run. I began fixing errors but gave up on the pygame.draw.color() error. What version of Python and Pygame are you using? \$\endgroup\$
    – Ian Moote
    Jul 23, 2022 at 19:18
  • 1
    \$\begingroup\$ Instead of calling clock.tick(fps), try calling clock.tick_busy_loop(fps). \$\endgroup\$
    – Vaillancourt
    Jul 23, 2022 at 23:02
  • 1
    \$\begingroup\$ @Ogorf I'll be spending a lot more time investigating this today because I find this problem both intriguing and challenging. As I said, the code I wrote independently moved the ball smoothly across the screen so it will be interesting to discover what it is in your code that is causing this problem. My answer got voted down as poor quality so I will not be replying further to this question, but I will be watching to see what insights others can provide on it. I hope you get a quality answer soon. \$\endgroup\$
    – Ian Moote
    Jul 24, 2022 at 13:24
  • 1
    \$\begingroup\$ I tried your code. I see jitter. I also printed the result of pygame.draw.circle, and glanced over the results; as it's been mentioned, it works in integers, and since you supply float values, the fraction part will likely be chopped off or rounded during the rendering. That being said, over the course of the test, the distance is consistent with the speed set. Aside from the suggestion I made previously, you could also pass in 1000.0/self.fps to self.tick instead of dt to have a more consistent update. \$\endgroup\$
    – Vaillancourt
    Jul 25, 2022 at 1:25

0

You must log in to answer this question.

Browse other questions tagged .