在 pygame 上使用 'blit' 时出现意外语法错误
Unexpected syntax error while using 'blit' on pygame
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 顺便说一句)
前一行缺少右括号:
img = pygame.transform.scale(img, (20,20)
# ^ ^ ^?
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 顺便说一句)
前一行缺少右括号:
img = pygame.transform.scale(img, (20,20)
# ^ ^ ^?