I’m using Python 2.7 and Pygame 1.9.1
The fact that there are a few things that pygame and IDLE do not like each other is irrelevant as I attempted to run it as a .py file as well.
This works:
import pygame
y = 0
dir = 1
running = 1
width = 800
height = 600
screen = pygame.display.set_mode((width, height))
linecolor = 255, 0, 0
bgcolor = 0, 0, 0
while running:
event = pygame.event.poll()
if event.type == pygame.QUIT:
running = 0
screen.fill(bgcolor)
pygame.draw.line(screen, linecolor, (0, y), (width-1, y))
y += dir
if y == 0 or y == height-1: dir *= -1
pygame.display.flip()
But this does not work:
import pygame
y = 0
dir = 1
running = 1
width = 800
height = 600
linecolor = 255, 0, 0
bgcolor = 0, 0, 0
screen = pygame.display.set_mode((640, 400))
while running:
event = pygame.event.poll()
if event.type == pygame.QUIT:
running = 0
screen.fill(bgcolor)
pygame.draw.aaline(screen, linecolor, (0, y), (width-1, y)
y += dir
if y == 0 or y == height-1: dir *= -1
pygame.display.flip()
Could anybody explain the differences and why one works over the other?
The only diffrence appears to be the the two lines locations:
linecolor = 255, 0, 0
and
bgcolor = 0, 0, 0
But that’s not the only difference. This is a syntax error:
It also differs from the above in that it calls
aalineinstead oflineand is indented 8 spaces instead of 4. Any of these differences could be causing a problem (since the 8-space indention, to me, suggest a possible mix of tabs and spaces.)Also, in general, it’s a good idea to post a stack trace when you get an error from a piece of code. They contain useful information.