Pygame.Surface 快把我逼疯了
Pygame.Surface driving me crazy
如果我只做 image.load('').convert_alpha(),我可以让我所有的图像出现。
当我尝试获得更多控制时,Surface 简直要了我的命,我不知道该怎么做。我需要帮助,拜托!!
import pygame, sys
pygame.init()
white = ((250,250,250))
black = ((0,0,0))
w = 800
h = 600
moveX = 0
moveY = 0
screen = pygame.display.set_mode((w,h))
pygame.display.set_caption('Paws')
background = pygame.image.load('C:/PythonImg/10121.jpg').convert()
clock = pygame.time.Clock()
Phil = pygame.image.load('C:/PythonImg/Phil_blob.png').convert_alpha()
Philpos = pygame.rect.Rect(0, 0, 400,300)
def Phil((Philpos), Phil):
screen.blit(Phil, (Philpos))
while pygame.display.get_init():
pygame.event.pump()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.display.get_init() == False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
moveX = -10
elif event.key == pygame.K_RIGHT:
moveX = 10
elif event.key == pygame.K_UP:
moveY = -10
elif event.key == pygame.K_DOWN:
moveY = 10
if event.type == pygame.KEYUP:
moveX = 0
moveY = 0
Philpos.move_ip(moveX, moveY)
Philpos.clamp_ip(screen.get_rect())
screen.fill(black)
screen.blit(background, (0,0))
Phil(Philpos, Phil)
pygame.display.update()
clock.tick(30)
pygame.QUIT()
quit()
听到我最近的错误
Traceback (most recent call last):
File "C:\Python27\Paws.py", line 57, in <module>
Phil(Philpos, Phil)
File "C:\Python27\Paws.py", line 28, in Phil
screen.blit(Phil, (Philpos))
TypeError: argument 1 must be pygame.Surface, not function
您将 Surface 存储在一个名为 Phil 的变量中,然后创建一个同名函数。
不要这样做。为您的函数重新命名或将其删除。
如果我只做 image.load('').convert_alpha(),我可以让我所有的图像出现。 当我尝试获得更多控制时,Surface 简直要了我的命,我不知道该怎么做。我需要帮助,拜托!!
import pygame, sys
pygame.init()
white = ((250,250,250))
black = ((0,0,0))
w = 800
h = 600
moveX = 0
moveY = 0
screen = pygame.display.set_mode((w,h))
pygame.display.set_caption('Paws')
background = pygame.image.load('C:/PythonImg/10121.jpg').convert()
clock = pygame.time.Clock()
Phil = pygame.image.load('C:/PythonImg/Phil_blob.png').convert_alpha()
Philpos = pygame.rect.Rect(0, 0, 400,300)
def Phil((Philpos), Phil):
screen.blit(Phil, (Philpos))
while pygame.display.get_init():
pygame.event.pump()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.display.get_init() == False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
moveX = -10
elif event.key == pygame.K_RIGHT:
moveX = 10
elif event.key == pygame.K_UP:
moveY = -10
elif event.key == pygame.K_DOWN:
moveY = 10
if event.type == pygame.KEYUP:
moveX = 0
moveY = 0
Philpos.move_ip(moveX, moveY)
Philpos.clamp_ip(screen.get_rect())
screen.fill(black)
screen.blit(background, (0,0))
Phil(Philpos, Phil)
pygame.display.update()
clock.tick(30)
pygame.QUIT()
quit()
听到我最近的错误
Traceback (most recent call last):
File "C:\Python27\Paws.py", line 57, in <module>
Phil(Philpos, Phil)
File "C:\Python27\Paws.py", line 28, in Phil
screen.blit(Phil, (Philpos))
TypeError: argument 1 must be pygame.Surface, not function
您将 Surface 存储在一个名为 Phil 的变量中,然后创建一个同名函数。
不要这样做。为您的函数重新命名或将其删除。