我開始學習pygame的和Python,最近我收到此錯誤信息:「TypeError:必須是pygame.Surface,而不是元組」該怎麼辦? (pygame的起動器)
"TypeError: must be pygame.Surface, not tuple"
這是代碼的一部分,給予我的錯誤:
# circles basic setup
circle = screen, white
radius = 5.5
surface = 10, 10
pygame.draw.circle(surface, white, (183, 218), 0, 5)
全代碼:
import pygame, time
from pygame import mixer, surface
pygame.init()
# define colors
red = (255, 255, 255)
white = (255, 255, 255)
black = (0, 0, 0)
# define size's
widthScreen, heightScreen = 368, 406
# define sounds
movingSound = "Pacman Waka Waka.mp3"
# setup
pygame.init()
screen = pygame.display.set_mode((widthScreen, heightScreen))
pygame.display.set_caption("PacMan Goes")
screen.fill(white)
pygame.draw.rect(screen, red, (0, 0, widthScreen, heightScreen), 5)
pac = pygame.image.load("pacman.png")
pac = pygame.transform.scale(pac, (22, 22))
pac_rect = pac.get_rect()
pac_rect.move_ip(173, 218)
mixer.init()
mixer.music.load('pacManSong.mp3')
mixer.music.play()
# speed in pixels per frame
x_speed = 0
y_speed = 0
# define Background
bg = pygame.image.load("pacmanBackground.jpg").convert()
bg = pygame.transform.scale(bg, (widthScreen, heightScreen))
openScreen = pygame.image.load("Pac-Man_Logo.PNG")
# circles basic setup
position = (183, 218)
radius = 5 # expected integer
border_size = 5
pygame.draw.circle(screen, white, position, radius, border_size)
time.sleep(4)
game_on = True
# -------------- Main Program Loop -------------- #
while game_on:
# --- Event Processing --- #
screen.fill(white)
event = pygame.event.poll()
if event.type == pygame.QUIT:
game_on = False
# user pressed down on a key
elif event.type == pygame.KEYDOWN:
# figure out if that was an arrow key, if so
# adjust speed.
if event.key == pygame.K_LEFT:
pac = pygame.image.load("pacmanLeft.png")
pac = pygame.transform.scale(pac, (20, 20))
mixer.music.load('Pacman Waka Waka.mp3')
mixer.music.play()
pygame.mixer.music.rewind()
x_speed = -3
elif event.key == pygame.K_RIGHT:
mixer.music.load(movingSound)
mixer.music.play()
pygame.mixer.music.rewind()
pac = pygame.image.load("pacman.png")
pac = pygame.transform.scale(pac, (20, 20))
x_speed = 3
elif event.key == pygame.K_UP:
mixer.music.load(movingSound)
mixer.music.play()
pygame.mixer.music.rewind()
pac = pygame.image.load("Up.png")
pac = pygame.transform.scale(pac, (20, 20))
y_speed = -3
elif event.key == pygame.K_DOWN:
pac = pygame.image.load("Down.png")
pac = pygame.transform.scale(pac, (20, 22))
mixer.music.load(movingSound)
mixer.music.play()
pygame.mixer.music.rewind()
y_speed = 3
# user let up on a key
elif event.type == pygame.KEYUP:
#if it is an arrow key reset vector back to 0
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
x_speed = 0
elif event.key == pygame.K_UP or event.key == pygame.K_DOWN:
y_speed = 0
if pac_rect.right >= widthScreen or pac_rect.right <= 0 and pac_rect.left >= widthScreen or pac_rect.left <= 0:
x_speed *= -1
if pac_rect.bottom >= heightScreen or pac_rect.bottom <= 0 and pac_rect.top >= heightScreen or pac_rect.top <= 0:
y_speed *= -1
pac_rect = pac_rect.move(x_speed, y_speed)
screen.blit(bg, (0, 0))
screen.blit(pac, pac_rect)
pygame.display.flip()
pygame.display.update()
pygame.time.wait(10)
BTW:你畫在白色背景下的白色圓圈,所以你不能看到它:) – furas
pygame的不會直接將顯示器上,但緩衝,你必須使用'pygame的。 display.flip()'或'pygame。 display.update()'在監視器上發送緩衝區。你不使用pygame。 display.update()'在'time.sleep(4)'之前'因此它不會在監視器上發送圓。在'time.sleep(4)'之後''你使用'pygame。 display.update()'但首先你使用'screen.fill(white)',這樣它就從緩衝區中刪除了圓。 – furas
錯誤消息很自我描述。 –