2

代码:

import pygame, sys

def load ():
    image = pygame.image.load ('ShrinSprite.jpg')
    return image, image.get_rect ()


class Sprite (pygame.sprite.Sprite):
    def __init__ (self):
        pygame.sprite.Sprite.__init__ (self)
        self.image, self.rect = load ()

sprite = Sprite ()
allsprites = pygame.sprite.RenderClear ((sprite))

Surface = pygame.display.set_mode ((400, 400), 0, 32)

 while True:
    Surface.fill ((255, 255, 255))
    allsprites.draw (0, 0)

    for event in pygame.event.get ():
        if event.type == QUIT:
            pygame.quit ()
            sys.exit (0)

         if event.type == KEYDOWN:
            allsprites.draw (0, -5)
            allsprites.clear ()

    pygame.display.update ()

该错误指出无法加载图像:

pygame.error: Could not load 'ShrinSprite.jpg'

虽然图片和程序在同一个目录下,但是还是一直出现这个错误

4

1 回答 1

4

This usually happens after you try to enter a command into the shell after running a program. To make it load, simply re-save the program.

Please let me know if this works.

于 2012-09-09T17:50:47.240 回答