【问题标题】:Unexpected syntax error while using 'blit' on pygame [closed]在pygame上使用'blit'时出现意外的语法错误[关闭]
【发布时间】:2015-05-06 14:12:41
【问题描述】:
import pygame
import sys
from pygame.locals import *

pygame.init()

white = (255,255,255)
black = (0,0,0)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
yellow = (255,255,0)
cyan = (0,255,255)
purple = (255,0,255)

bg = black

fps = 30
dispWidth = 800
dispHeight = 600
pixMove = 10

UP = 'up'
DOWN = 'down'
LEFT = 'left'
RIGHT = 'right'

def runGame():
    imgx = 3
    imgy = 3
    direction = RIGHT

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

            elif event.type == KEYDOWN:
                if event.key == (K_LEFT or K_a):
                    direction = LEFT
                elif event.key == (K_RIGHT or K_d):
                    direction = RIGHT
                elif event.key == (K_DOWN or K_s):
                    direction = DOWN
                elif event.key == (K_UP or K_w):
                    direction = UP

            if direction == UP:
                imgy -= pixMove
            elif direction == DOWN:
                imgy += pixMove
            elif direction == LEFT:
                imgx -=pixMove
            elif direction == RIGHT:
                imgx += pixMove

            setDisplay.fill(bg)
            img = pygame.image.load('kirby.png')
            img = pygame.transform.scale(img, (20,20)
            setDisplay.blit(img,(imgx,imgy))
            pygame.display.update()

while True:
    global fpsTime
    global setDisplay

    fpsTime = pygame.time.Clock()
    setDisplay = pygame.display.set_mode((dispWidth,dispHeight))
    pygame.display.set_caption('kirby\'s controlled adventure')
    runGame()

好的,当我运行此代码时,我在“setDisplay.blit(img, (imgx,imgy))”(更具体地说是在 setDisplay 之后)出现语法错误。

我不知道这段代码到底出了什么问题,谁能帮帮我?

(我正在使用 python 3.4 顺便说一句)

【问题讨论】:

    标签: python python-3.x pygame python-3.4


    【解决方案1】:

    您在前一行缺少右括号:

    img = pygame.transform.scale(img, (20,20)
    #                           ^     ^     ^?
    

    【讨论】:

    • 我的天啊,谢谢(我现在觉得自己太笨了……)
    猜你喜欢
    • 2013-01-11
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    • 2013-07-21
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 2014-06-15
    相关资源
    最近更新 更多