#๐Ÿ”’ Pygame not running smoothly

19 messages ยท Page 1 of 1 (latest)

paper island
#

Hello, im following a tutorial off youtube: "The ultimate introduction to pygame", in my code a sky, ground and snail are blitted onto the screen, then the snail is moved along the x axis, my problem is the snail is not moving slowly, even at lower frame rates, my computer is powerful enough to run this so i dont know why this is happening, any resources you may need to test my code are attached, thanks.

import pygame
from sys import exit

pygame.init()
screen = pygame.display.set_mode((800,400))
pygame.display.set_caption('Runner')
clock = pygame.time.Clock()
test_font = pygame.font.Font('font\Pixeltype.ttf',50)

sky_surface = pygame.image.load('graphics\Sky.png')
ground_surface = pygame.image.load('graphics\ground.png')
text_surface = test_font.render('My game',False,'Black')

snail_surface = pygame.image.load('graphics\snail\snail1.png')
snail_x_pos = 600

while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()

    screen.blit(ground_surface,(0,300))
    screen.blit(sky_surface,(0,0))
    screen.blit(text_surface,(300,50))
    snail_x_pos -= 4
    if snail_x_pos < -100: snail_x_pos = 800
    screen.blit(snail_surface,(snail_x_pos,264))
        
pygame.display.update()
clock.tick(60)
tropic surgeBOT
#

@paper island

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

signal crane
#

It's difficult to notice but I think the following lines need to be un-indented one time so they are outside of the for loop above thempy screen.blit(ground_surface,(0,300)) screen.blit(sky_surface,(0,0)) screen.blit(text_surface,(300,50)) snail_x_pos -= 4 if snail_x_pos < -100: snail_x_pos = 800 screen.blit(snail_surface,(snail_x_pos,264))

paper island
#

ill try that

signal crane
#

Poor disord formatting on them, but just un indent them once so they align with the pygame.display.update() beneath them

paper island
#

yeah thank you that has fixed it

signal crane
#

Nice, good luck

paper island
#

can i ask how the it was working at all if they were indented

#

didnt mean to put the

#

i would have thought it cant blit anything onto the screen if it doesnt match any indentation

#

ohhh

#

i think i understamd it was only checking for every event in pygame

signal crane
#

Because the event loop is running during every game loop, so it's two loops, one inside the other

paper island
#

yes thank you

signal crane
#

Right on

paper island
#

have a good day

signal crane
#

You too

tropic surgeBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.