Python Forum
[PyGame] sound effect delay and program laggy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] sound effect delay and program laggy
#6
(Sep-27-2019, 12:08 AM)xBlackHeartx Wrote: I did originally use time.delay to slow down the game, but that caused input lag, which was fixed when I changed the code to instead reduce the framerate. And I needed to set the framerate that low just to keep the program from running insanely fast. I am running this on a high-end gaming pc, as I've already stated. Not having any kind of limit just made the program way too fast to play. Honestly, even that low of a framerate is a bit fast for me.
60 FPS on my machine is the same as 60 FPS on your machine regardless of what each specs are. That is the point to limiting it, so that yours is limited to 60, and not 200X times faster being a beefy PC. The point of putting in 60 is to limit it up to 60 FPS so that the specs of each computer does not change the rate, but are consistent between all computers. The only PC's that would have trouble are older computers that cannot keep up your game. By inserting 7 FPS you are restricting your game to a really low frame rate. You can always reduce speed, but cannot ever gain back those framerates that never exist.

(Sep-27-2019, 12:08 AM)xBlackHeartx Wrote: I did originally use time.delay to slow down the game, but that caused input lag,
I repeat: You dont change the speed by changing your framerate as i said earlier. You slow down your moving objects by delaying them. If there is a problem after that, the answer is not to revert the framerate back to a lower number. You put a band-aid on it by reducing the framerate when you should of fixed the real problem. What input lag? You would have to define this more to properly diagnose it. Show your code as you had it when you had this problem with the framerate at 60. When i change your code to 60 FPS, the snake just needs to be slowed down. This can be simply done by comparing ticks every frame.
        if pygame.time.get_ticks()-timer > delay:
            timer = pygame.time.get_ticks()
            snake.move()
Without a snake class and using nested while loops for game states.... your code is hard to read.

How did you get a certificate for C++ and Java without learning classes? Both use OOP. Classes are very powerful and would improve your code dramatically. It would remove all globals from your code, reduce redundancy of your code down to probably 100-150 lines, make it easier to read and maintain, and make it more adaptable to add more things. For example if i want to modify your snake's logic (like slow it down because of raising the FPS) i have to look through your entire code. It should be in a Snake class as data. You also are not using pygame rects for position coordinates as well as collision (which would reduce code even further).

This is an example of snake with classes. It is very readable being in classes.
Recommended Tutorials:


Messages In This Thread
RE: Why do my sound effects always have a slight delay in them? - by metulburr - Sep-27-2019, 03:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Laggy Game Movement game_slayer_99 12 4,791 Oct-05-2022, 11:34 AM
Last Post: metulburr
Music [PyGame] Chopper wash effect efficiency questions. michael1789 9 4,634 Jan-19-2021, 07:12 PM
Last Post: michael1789
  Appropriately delay this PyGame code kleynah22 2 4,516 Nov-09-2017, 02:00 PM
Last Post: Windspar
  [PyGame] My program is very laggy GamePlanet 6 7,255 Aug-15-2017, 03:00 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020