我不明白这里有什么问题
这是我的代码,我已经看了几个小时了。这可能是 Lion 的 python bug。我正在使用Python 2.7。
import os, pygame
from pygame.locals import *
import spritesheet
import sound
from map import Level
level = Level()
level.loadFile("level.map")
pygame.init()
screen = pygame.display.set_mode((640, 480))
background = level.render(spritesheet.spritesheet("spritesheet.bmp"))
pygame.display.set_caption('Game')
character=spritesheet.spritesheet("spritesheet.bmp").image_at(pygame.rect.Rect(64, 64, 32, 32), colorkey = (255, 255, 255))
#Create The Backgound
background.blit(character, (304, 224))
screen.blit(background, (0, 0))
clock = pygame.time.Clock()
level.setTile(1, 1, "3")
pygame.display.flip()
xoffset=0
yoffset=0
while True:
background = level.render(spritesheet.spritesheet("spritesheet.bmp"))
background.blit(character, (304, 224))
screen.blit(background, (0+xoffset, 0+yoffset))
pygame.display.flip()
for event in pygame.event.get():
if event.type==QUIT:
exit()
elif event.type == KEYDOWN:
if event.key == K_w:
yoffset-=5
if event.key == s:
yoffset+=5
它返回:
File "main.py", line 30
elif event.type == KEYDOWN:
^
IndentationError: unindent does not match any outer indentation level
我找不到任何问题。
This is my code that I have looked through for a couple of hours. It may be a python bug for Lion. I am using python 2.7.
import os, pygame
from pygame.locals import *
import spritesheet
import sound
from map import Level
level = Level()
level.loadFile("level.map")
pygame.init()
screen = pygame.display.set_mode((640, 480))
background = level.render(spritesheet.spritesheet("spritesheet.bmp"))
pygame.display.set_caption('Game')
character=spritesheet.spritesheet("spritesheet.bmp").image_at(pygame.rect.Rect(64, 64, 32, 32), colorkey = (255, 255, 255))
#Create The Backgound
background.blit(character, (304, 224))
screen.blit(background, (0, 0))
clock = pygame.time.Clock()
level.setTile(1, 1, "3")
pygame.display.flip()
xoffset=0
yoffset=0
while True:
background = level.render(spritesheet.spritesheet("spritesheet.bmp"))
background.blit(character, (304, 224))
screen.blit(background, (0+xoffset, 0+yoffset))
pygame.display.flip()
for event in pygame.event.get():
if event.type==QUIT:
exit()
elif event.type == KEYDOWN:
if event.key == K_w:
yoffset-=5
if event.key == s:
yoffset+=5
It returns this:
File "main.py", line 30
elif event.type == KEYDOWN:
^
IndentationError: unindent does not match any outer indentation level
I can't find anything wrong with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保没有混合使用制表符和空格进行缩进。您的编辑器可能会认为您的制表位是一个值(4?),而 python 解释器可能认为是其他值;如果你的某些行用空格缩进,而其他行用制表符缩进,当 python 解释器不同意时,你的编辑器将显示内容是排队的。
Make sure you are not mixing tabs and spaces for indentation. It is possible that your editor may think your tab stop is one value (4?), and the python interpreter some other value; if some of your lines are then indented with spaces, and other lines with tabs, your editor will show things as lining up when the python interpreter disagrees.
您的代码看起来正确。通过运行 $ python -t yourcode.py 来验证空格和制表符是否未混合。这打开了选项卡保姆。
Your code looks correct. Verify that spaces and tabs haven't been intermixed by running
$ python -t yourcode.py
. This turns on the tab nanny.