[Python / PYGAME ERROR] pygame binascii.error:填充不正确 [英] [Python/PYGAME ERROR] pygame binascii.error: incorrect padding

查看:76
本文介绍了[Python / PYGAME ERROR] pygame binascii.error:填充不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我正在使用pygame创建一个游戏。请注意我是游戏开发和编程的新手。



我正在使用Tiled为我的游戏创建一个平铺地图。但是,当我尝试使用pygame运行我的程序时会发生此错误:

Hi! I am creating a game using pygame. Please do note that I am new to game development and programming.

I'm using Tiled to create a tile map for my game. However, this error occurs when I try to run my program with pygame:

Traceback (most recent call last):
File "C:\Users\Rose\Desktop\mp2 sh*ts\sh*t.py", line 114, in <module>
Game().main(screen)
File "C:\Users\Rose\Desktop\mp2 sh*ts\sh*t.py", line 58, in main
self.tilemap = tmx.load('tileMap.tmx', screen.get_size())
File "C:\Users\Rose\Desktop\mp2 sh*ts\tmx.py", line 835, in load
return TileMap.load(filename, viewport)
File "C:\Users\Rose\Desktop\mp2 sh*ts\tmx.py", line 714, in load
layer = Layer.fromxml(tag, tilemap)
File "C:\Users\Rose\Desktop\mp2 sh*ts\tmx.py", line 255, in fromxml
data = data.decode('base64').decode('zlib')
File "C:\Python27\lib\encodings\base64_codec.py", line 42, in base64_decode
output = base64.decodestring(input)
File "C:\Python27\lib\base64.py", line 325, in decodestring
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
[Finished in 5.0s]





我的代码看起来像这样:





My code looks like this:

import pygame
import tmx

class Player(pygame.sprite.Sprite):
def __init__(self, location, *groups):
    super(Player, self).__init__(*groups)
    self.image = pygame.image.load('red.gif').convert()
    self.rect = pygame.rect.Rect(location, self.image.get_size())
    self.resting = False 
    self.dy = 0 

def update(self, dt, game):
    last = self.rect.copy()

    key = pygame.key.get_pressed()
    if key[pygame.K_LEFT]:
        self.rect.x -= 150 * dt
    if key[pygame.K_RIGHT]:
        self.rect.x += 150 * dt

    if self.resting and key[pygame.K_SPACE]:
        self.dy = -500
    self.dy = min(400, self.dy + 40)

    self.rect.y += self.dy * dt

    new = self.rect
    self.resting = False
    for cell in game.tilemap.layers['triggers'].collide(new, 'blockers'):
        if last.right <= cell.left and new.right > cell.left:
            new.right = cell.left
        if last.left >= cell.right and new.left < cell.right:
            new.left = cell.right
        if last.bottom <= cell.top and new.bottom > cell.top:
            self.resting = True
            new.bottom = cell.top
            self.dy = 0
        if last.top >= cell.bottom and new.top < cell.bottom:
            new.top = cell.bottom
            self.dy = 0

    game.tilemap.set_focus(new.x, new.y)

class Game(object):
def main(self, screen):
    clock = pygame.time.Clock()

    background = pygame.image.load('bg.png')

    self.tilemap = tmx.load('tileMap.tmx', screen.get_size())

    self.sprites = tmx.SpriteLayer()
    start_cell = self.tilemap.layers['triggers'].find('player')[0]
    self.player = Player((start_cell.px, start_cell.py), self.sprites)
    self.tilemap.layers.append(self.sprites)

    fps = 30
    running = True
    while running:
        dt = clock.tick(fps)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                running = False

        self.tilemap.update(dt/1000., self)
        pygame.display.set_caption("Little Red")
        screen.blit(background, (0,0))
        self.tilemap.draw(screen)
        pygame.display.flip()

if __name__ == '__main__':
    pygame.init()
    width = 1024
    height = 480
    screen = pygame.display.set_mode((width, height))
    Game().main(screen)







这里是tmx.py的链接/ tmx我用过的文件。



这个 youtube video 担任我的导游。



最后,是我的地图的样子。





提前感谢那些愿意回答这个问题的人!



我尝试了什么:



我试图寻找解决此错误的可能方法,但我还没找到具体解决方案。




Here is the link to the tmx.py/tmx file I used.

This youtube video served as my guide.

Lastly, this is how my map looks like.


Thank you in advance to those who would answer this question!

What I have tried:

I have tried searching for possible ways to troubleshoot this error, but I'm yet to find a concrete solution.

推荐答案

参见 binascii.Error:填充不正确 - Google搜索 [ ^ ]。


这篇关于[Python / PYGAME ERROR] pygame binascii.error:填充不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆