|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import pygame
import sys
pygame.init()
size = width, height = 600, 400
speed = [-2, -1]
bg = (255, 255, 255)
screen = pygame.display.set_caption('初次见面,请大家多多关照!')
dog = pygame.image.load('dog.jpg')
position = dog.get_rect()
while True:
for event in pygame.event.get():
if event.type == pygame.QUITE:
sys.exit()
position = position.move(speed)
if position.left < 0 or position.right > width:
dog = pygame.transform.flip(dog, True, False)
speed[0] = -speed[0]
if position.top < 0 or position.bottom > height:
speed[1] = -speed[1]
screen.fill(bg)
screen.blit(dog, position)
pygame. display.flip()
pygame.time.delay(10)
大部分是按照小甲鱼课程的代码码上去的,但是却运行不了得到了
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:/Users/betterman/Desktop/9.3", line 31, in <module>
screen.fill(bg)
AttributeError: 'NoneType' object has no attribute 'fill'
参考代码:
import pygame
import sys
pygame.init()
size = width, height = 600, 400
speed = [-2, -1]
bg = (255, 255, 255)
screen = pygame.display.set_mode(size)
pygame.display.set_caption('初次见面,请大家多多关照!')
dog = pygame.image.load('dog.jpg')
position = dog.get_rect()
while True:
for event in pygame.event.get():
if event.type == pygame.K_QUOTE:
sys.exit()
position = position.move(speed)
if position.left < 0 or position.right > width:
dog = pygame.transform.flip(dog, True, False)
speed[0] = -speed[0]
if position.top < 0 or position.bottom > height:
speed[1] = -speed[1]
screen.fill(bg)
screen.blit(dog, position)
pygame. display.flip()
pygame.time.delay(10)
|
|