1

I cant blit anything to my pygame screen using studio code on my mac. Is this a known issue or is there a way to fix it I am overlooking? I'm not getting any errors it's just not doing anything. I am kinda new to pygame so anything could work. here's my code:

pygame.display.set_caption('The space Simulator')

red=(255, 0, 0)
white=(255, 255, 255)
black=(0, 0, 0)
green=(0, 255, 0)
blue=(0, 0, 255)
image = pygame.image.load(r'/Users/Mr.Penguin280/Desktop/Photos/Logo.jpg')
screen = pygame.display.set_mode([1000, 1000])
background = pygame.Surface((1000,1000))
text1 = myfont.render('WELCOME TO MY SIMULATOR.', True, red)
textpos = text1.get_rect()
textpos.centerx = background.get_rect().centerx





running=True

while running:
    screen.blit(image, (textpos))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
  • I have the pygame.init and pygam.font.init off the code that I inputed along with the code that sets up the "myfont" variable – MrPenguin280 Nov 10 '20 at 19:30
  • 1
    Welcome to stack overflow. It is good practice to provide a self-contained but small example of your code so people can try to run it, see https://stackoverflow.com/help/minimal-reproducible-example – piterbarg Nov 10 '20 at 20:42

1 Answers1

0

You're just not flushing / updating the drawing primitives to the screen. Really you just need a pygame.display.update() or pygame.display.flip() after all your blits are done.

I guess you removed parts of your code to keep it simple for the question, but I put them back in for a working answer.

I also re-arranged the code, and removed the creation of the background Surface just to get the centre co-ordinate. This operation can be performed on the existing screen Surface.

import pygame
  
red=(255, 0, 0)
white=(255, 255, 255)
black=(0, 0, 0)
green=(0, 255, 0)
blue=(0, 0, 255)

pygame.init()
pygame.display.set_caption('The space Simulator')
screen = pygame.display.set_mode([1000, 1000])

#image = pygame.image.load(r'/Users/Mr.Penguin280/Desktop/Photos/Logo.jpg')
image  = pygame.image.load('background.png' ).convert()
image  = pygame.transform.smoothscale( image, (1000,1000) )
#background = pygame.Surface((1000,1000))

myfont  = pygame.font.SysFont( None, 24 )
text1   = myfont.render('WELCOME TO MY SIMULATOR.', True, red)
textpos = text1.get_rect()
textpos.centerx = screen.get_rect().centerx


running=True

while running:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    screen.blit(image, (0,0))
    screen.blit(text1, (textpos))

    pygame.display.flip()

pygame.quit()
Kingsley
  • 14,398
  • 5
  • 31
  • 53