0

2D タイルベースのプラットフォーマーを作成して、Python と Pygame を学ぼうとしています。現在、「タイルベース」の部分で立ち往生しています。これは私のコードです:

import pygame, sys
from pygame.locals import *

#Just defining some variables
windowWidth = 640
windowHeight = 480
mapWidth = windowWidth // 32
mapHeight = windowHeight // 32
tilesize = 32
speed = [1, 1] #Array/List declaration
black = (0,0,0) #Tuple declaration

#intended to create a 2d list of subsurfaces    
def create_map():
    floor = pygame.image.load("rect_gray0.png")
    map = []
    for x in range(mapWidth):
        line = []
        map.append(line)
        for y in range(mapHeight):
            line.append(floor.subsurface((0,0,tilesize,tilesize)))

    return map


if __name__ == '__main__':

    pygame.init()
    print("Initializing")

    screen = pygame.display.set_mode((windowWidth, windowHeight))
    map = create_map()

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

        screen.fill(black)

        for x in range(mapWidth):
            for y in range(mapHeight):
                #for each subsurface in the map, blit it to the screen.
                tile = map[x][y]
                screen.blit(tile, (x*tilesize, y*tilesize))

        screen.display.flip() 

コードを実行すると、次のエラーが表示されます。

Traceback (most recent call last):
  File "C:\Users\dementeddr\workspace\TheWaterIsRising\src\default\RisingMain.py", line 59, in <module>
    screen.display.flip() 
AttributeError: 'pygame.Surface' object has no attribute 'display'

私はグーグルで検索しましたが、他の多くの属性エラーを見てきましたが、「表示」属性については何もありません。私は何を間違っていますか?

4

1 に答える 1

1

エラーメッセージは、あなたが知る必要があるすべてを教えてくれます:

Traceback (most recent call last):
  File "C:\Users\dementeddr\workspace\TheWaterIsRising\src\default\RisingMain.py", line 59, in <module>
    screen.display.flip() 

上記の部分は、問題が発生した正確なコード行を示していますscreen.display.flip()

AttributeError: 'pygame.Surface' object has no attribute 'display'

screenは typepygame.Surfaceであり、属性を持たないdisplayため、何かが間違っています。http://www.pygame.org/docs/tut/intro/intro.htmlなどのチュートリアルを見ると、代わりにpygame.display.flip()を呼び出す必要があることがわかります。その行を置き換えてみて、実行されるかどうかを確認してください。

幸運を :)

于 2014-06-11T00:48:18.233 に答える