簡體   English   中英

精靈未顯示在pygame和無效的rectstyle對象中

[英]sprite not showing up in pygame & invalid rectstyle object

我正在關注PyGame上的一個教程,在其中一個教程中,我們正在創建一個簡單的Space Invaders游戲。 我有幾個問題。

  1. 屏幕上不會顯示太空飛船的精靈,並且2.我收到錯誤消息。 (有關以下內容的更多詳細信息)

碼:

import pygame, sys
from pygame.locals import *

clock = pygame.time.Clock() #framerate

size = x,y=800,600
screen = pygame.display.set_mode((size)) #creates window, with resolution of 1600,900

pygame.mouse.set_visible(0)

ship = pygame.image.load('ship.png')

ship_top = screen.get_height() - ship.get_height() #makes it so ship is in the centre at the bottom
ship_left = screen.get_width()/2 - ship.get_width()/2




while True: #main game loop
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    screen.fill(0,0,0)
    screen.blit(ship,(ship_left,ship_top))



    clock.tick(60)
    pygame.display.update

錯誤:

Traceback (most recent call last):
  File "D:\python_tuts\space_invaders.py", line 24, in <module>
    screen.fill(0,0,0)
ValueError: invalid rectstyle object

所以精靈不顯示,我得到那個錯誤。

謝謝,

fill方法如下所示:

fill(color, rect=None, special_flags=0) -> Rect

由於您這樣稱呼它:

screen.fill(0,0,0)

它將0分配給rect和special_flags。 我認為您打算這樣做:

screen.fill((0,0,0))

最好在代碼開始時定義顏色元組

BLACK = (0,0,0)
screen.fill(BLACK)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM