首先:我对编程完全不熟悉,我刚开始使用pygame。到目前为止,一切都很顺利,直到我试图加载背景图像。这是我的代码:任何帮助都会很棒!我不是真的看到了这个问题。编辑:我正在使用Mac OSX。
import pygame
import os
import sys
pygame.init()
screen = pygame.display.set_mode((800, 500))
caption = pygame.display.set_caption("Space Game")
done = False
y = 220
x = 10
delay = 0
circles = []
screen = pygame.display.get_surface()
background = os.path.join("/Users/user/Desktop/proj/space-game/realBackground.png")
background_surface = pygame.image.load(background).convert()
screen.blit(background_surface, (800, 220))
pygame.display.update()
clock = pygame.time.Clock()
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
pressed = pygame.key.get_pressed()
if pressed[pygame.K_UP]: y -= 10
if pressed[pygame.K_DOWN]: y += 10
screen.fill((0, 0, 0))
color = (0, 128, 255)
pygame.draw.rect(screen, color, pygame.Rect(x, y, 60, 60))
delay -= 1
if pressed[pygame.K_SPACE]:
if delay <= 0:
delay = 30
circles.append([70, y + 30])
for i in range(0, len(circles)):
circles[i][0] += 5
pygame.draw.circle(screen, (0,0,255), (circles[i][0], circles[i][1]), 15, 1)
pygame.display.flip()
clock.tick(60)