2
我已經開始學習pygame,並且我編寫了一個簡單的模擬時鐘。簡單的模擬時鐘變慢然後Pygame出現錯誤
import sys, pygame
pygame.init()
white = 255, 255, 255
size = width, height = 480, 480
screen = pygame.display.set_mode(size)
minute_hand = pygame.image.load('minute_hand.png')
minute_hand_rect = minute_hand.get_rect()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
center = minute_hand_rect.center
rotate = pygame.transform.rotate
minute_hand = rotate(minute_hand, -1)
minute_hand_rect = minute_hand.get_rect(center=center)
screen.fill(white)
screen.blit(minute_hand, minute_hand_rect)
pygame.display.update()
pygame.time.delay(100)
但我hand_clock得到了一會兒慢然後停止運行,並說:
Traceback (most recent call last):
File "clock.py", line 21, in <module>
minute_hand = rotate(minute_hand, -1)
pygame.error: Width or height is too large
顯然,我做的事情錯了,但我想不出哪裏不對。
這是因爲當您以90度以外的增量旋轉時,它會放大圖像大小以容納新的旋轉後的圖像 – Keatinge
增加屏幕的大小,使其足夠大,或使用較小的圖像,正如Racialz所說,旋轉會增加圖像的大小。 – marienbad