Answer the question
In order to leave comments, you need to log in
Why does my pygame game slow down?
I'm making a game based on Metiz's book (with which, probably, everyone has already got it))
And everything seems to be fine, but the result is displayed with ... I don't know ... 10 fps? Five? Two?
So I wonder if it's the python or me? Maybe I somehow rewrote the code from the book, which, nevertheless, works? Is it a cycle thing? Maybe you need to install fresh drivers for the vidyuhi))
maybe it's 4770k, 1070, 16RAM and you need to throw it in the trash and buy something more serious?
But seriously, is this how python + paygame works with simple animation? If so, then this is sad and there is no point in learning Python and taking it to motivate the game.
Or did I somehow crookedly rewrite the cycle? Well, I would have rewritten it crookedly - it would not have worked, probably. Could it be that some parenthesis in the wrong place (as an example) has that effect? I didn’t add any gag, I don’t know either Python or Paygame at such a level that I can improvise in such things.
Here is a video of what it looks like.
https://youtu.be/EK6q-e2Bh3k
Screen recording did not affect the FPS in any way.
Metiz himself does not indulge in fashionable things, like:
fpsClock = pg.time.Clock()
fpsClock.tick(360)
def start():
pg.init()
settings = Settings()
screen = pg.display.set_mode((settings.screen_width, settings.screen_height))
pg.display.set_caption('Space Inv version 2')
ship = Ship(settings, screen)
bullets = Group()
aliens = Group()
while True:
engine.check_events(settings, screen, ship, bullets)
ship.update_ship_pos()
engine.update_bullets(bullets)
# Вызываю метод создания армии пришельцев постоянно
engine.create_aliens_army(settings, screen, ship, aliens)
engine.update_screen(settings, screen, ship, aliens, bullets)
start()
def start():
pg.init()
settings = Settings()
screen = pg.display.set_mode((settings.screen_width, settings.screen_height))
pg.display.set_caption('Space Inv version 2')
ship = Ship(settings, screen)
bullets = Group()
aliens = Group()
# Метод создания армии пришельцев нужно вызывать только один раз
engine.create_aliens_army(settings, screen, ship, aliens)
while True:
engine.check_events(settings, screen, ship, bullets)
ship.update_ship_pos()
engine.update_bullets(bullets)
engine.update_screen(settings, screen, ship, aliens, bullets)
start()
Answer the question
In order to leave comments, you need to log in
Get it right. For those who run into the same situation, here's an explanation:
It's only me that's slow here, because
I ran the engine.create_aliens_army(settings, screen, ship, aliens) function of creating aliens in the main While loop, because of which all other loops were executed every nanosecond. I moved the call to create an army from the main loop and everything was fine.
Watch where you call methods.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question