繁体   English   中英

我不明白我在这里做错了什么

[英]I cannot understand what I have done wrong here

我正在学习Pygame,我无法理解如何解决这个问题。 我得到的只是一个黑屏。

import pygame, sys
from pygame.locals import *

pygame.init()

screen = pygame.display.set_mode((640,360),0,32)
pygame.display.set_caption("Game!")

bg = pygame.image.load("graphics/bg.bmp").convert()
chris = pygame.image.load("graphics/chris.bmp").convert_alpha()

x,y=0,0
movex, movey=0,0

while True:

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == KEYDOWN:
            if event.key==K_LEFT:
                movex=-1
            elif event.key==K_RIGHT:
                movex=+1
            elif event.key==K_UP:
                movey=-1
            elif event.key==K_DOWN:
                movey=+1
        if event.type==KEYUP:
            if event.key==K_LEFT:
                movex=0
            elif event.key==K_RIGHT:
                movex=0
            elif event.key==K_UP:
                movey=0
            elif event.key==K_DOWN:
                movey=0

    x+=movex
    y+=movey

    screen.blit(bg, (0,0))
    screen.blit(chris, (100, 100))

    pygame.display.update

我从中得到的只是一个黑屏。 bg.bmp是灰色背景图像,而chris是具有相同背景的字符。 这摘自NewBostons教程。 复制了所有内容。 我有Python 2.7和Pygame 1.9.2 64bit

请帮忙 :)

这个:

pygame.display.update

应该是:

pygame.display.update()
#                    ^^

没有括号; python在display上查找update属性,但不再执行其他操作; 加上括号,然后调用找到的属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM