我不明白这里有什么问题

发布于 2024-12-18 03:26:14 字数 1363 浏览 1 评论 0原文

这是我的代码,我已经看了几个小时了。这可能是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℉服软 2024-12-25 03:26:14

确保没有混合使用制表符和空格进行缩进。您的编辑器可能会认为您的制表位是一个值(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.

与君绝 2024-12-25 03:26:14

您的代码看起来正确。通过运行 $ 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文