代码:
import pygame
pygame.init()
WIDTH = 800
HEIGHT = 480
screen = pygame.display.set_mode((WIDTH,HEIGHT))
block = pygame.sprite.Sprite()
block.image = pygame.image.load('stone.png')
newblock = pygame.transform.scale(block, (64, 64))
newblock.rect = newblock.image.get_rect()
newblock.group = pygame.sprite.GroupSingle(newblock)
newblock.group.draw(screen)
pygame.display.update()
当我尝试使用pygame.transform.scale缩放图像时,它会给我这个错误:
Traceback (most recent call last):
File "C:/pygame/program.py", line 8, in <module>
newblock = pygame.transform.scale(block, (64, 64))
TypeError: must be pygame.Surface, not Sprite
答案 0 :(得分:0)
错误消息说明了一切。 pygame.transform.scale
的第一个参数必须是Surface
,但您传递的是Sprite
。
我想你想要这样的东西:
import pygame
pygame.init()
WIDTH = 800
HEIGHT = 480
screen = pygame.display.set_mode((WIDTH,HEIGHT))
img = pygame.image.load('stone.png')
block = pygame.sprite.Sprite()
block.image = pygame.transform.scale(img, (64, 64))
block.rect = block.image.get_rect()
group = pygame.sprite.GroupSingle(block)
while True:
#TODO: event handling
group.draw(screen)
pygame.display.update()