凋零落叶 发表于 2020-9-3 21:17:34

pygame求助

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 = -speed

    if position.top < 0 or position.bottom > height:
      speed = -speed

    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'

Twilight6 发表于 2020-9-4 00:53:11


参考代码:

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 = -speed

    if position.top < 0 or position.bottom > height:
      speed = -speed

    screen.fill(bg)
    screen.blit(dog, position)
    pygame. display.flip()
    pygame.time.delay(10)

凋零落叶 发表于 2020-9-4 09:21:17

Twilight6 发表于 2020-9-4 00:53
参考代码:

我知道哪里错了,感谢
页: [1]
查看完整版本: pygame求助