1

I'm new to programming, so I might be asking a silly question. I'm trying to make a game from "Python Crash Course", but when I am trying to run it, the graphics don't show. I tried to insert different print-messages, and can see that my loop is running. I reinstalled pygame, to make sure that it is not what is causing me problems.

I ran the script from visual studio code, from IDLE and the terminal, without any luck. I'm using a macbook with catalina. I sent it to my friend, who can run it without any problems on his linux system.

In VSC I can see, when I hover the mouse over screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height)), that it says display: MissingModule, but I can't seem to figure out what this means.

import pygame

from settings import Settings
from ship import Ship
import game_functions as gf

def run_game():
    """Initialize pygame, settings and screen object."""
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    # Make a ship
    ship = Ship(screen)

    # Start the main loop for the game.
    while True:
        gf.check_events(ship)
        ship.update()
        gf.update_screen(ai_settings, screen, ship)

        # Make the most recently drawn screen visible.
        pygame.display.flip()

run_game()

I get this traceback when I stop the program:

^CTraceback (most recent call last):
  File "/Users/camilla/Desktop/Projekter/AlienInvasion/alien_invasion.py", line 28, in <module>
  File "/Users/camilla/Desktop/Projekter/AlienInvasion/alien_invasion.py", line 23, in run_game

  File "/Users/camilla/Desktop/Projekter/AlienInvasion/game_functions.py", line 26, in update_screen
    screen.fill(ai_settings.bg_color)
martineau
  • 119,623
  • 25
  • 170
  • 301
Camilla
  • 11
  • 2
  • use while 1: instead of while True – Sina Farhadi Jan 17 '20 at 16:00
  • 1
    I just tried that, but it doesn't make any difference. – Camilla Jan 17 '20 at 16:02
  • You may have to call `pygame.init()` _before_ importing those other modules because they may depend on something it does. – martineau Jan 17 '20 at 16:51
  • Sadly it does not make any difference. Also, I suspect that the problem might not be in the code, since my friend runs the file without any problems on his computer. – Camilla Jan 17 '20 at 17:02
  • always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Jan 17 '20 at 17:17
  • usually Sprite or own class has method `.draw()` to display element but I don't see any `.draw()` in your code. – furas Jan 17 '20 at 17:19
  • I thought pygame.display.set_mode() was supposed to do that? I put in the traceback now, maybe that helps. I suspect that the problem is not in the code though, since it runs perfectly on my friends computer. – Camilla Jan 17 '20 at 17:24
  • is your friend using the same system - Widows/Linux/Mac ? – furas Jan 17 '20 at 17:38
  • Im using mac, he's using linux. – Camilla Jan 17 '20 at 18:54
  • problem can be Mac - so you should use Google to search i.e `Mac PyGame drawing problem` – furas Jan 17 '20 at 20:49
  • 1
    People have had some issues with the latest stable version of Pygame on Catalina. Try installing one of the development versions of Pygame: `python -m pip install pygame==2.0.0.dev6` – japhyr Jan 18 '20 at 15:40

0 Answers0