Python Pygame在blitting期间返回锁定错误

Python Pygame在blitting期间返回锁定错误,python,pygame,pygame-surface,Python,Pygame,Pygame Surface,我试图在pygame中制作一个2D游戏,并且有一个具有surface属性的camera类,每次更新相机时,其曲面都会更新。所有图形都会快速显示到game.worldsface,然后主摄像头会对其拍照并快速显示到显示界面。然而,当使用其他相机时,我无法快速到达世界表面并获得锁定错误。我已经试过了。解锁()。这可能是什么原因造成的 import pygame import pickle class Tileset: def __init__(self, location):

我试图在pygame中制作一个2D游戏,并且有一个具有surface属性的camera类,每次更新相机时,其曲面都会更新。所有图形都会快速显示到game.worldsface,然后主摄像头会对其拍照并快速显示到显示界面。然而,当使用其他相机时,我无法快速到达世界表面并获得锁定错误。我已经试过了。解锁()。这可能是什么原因造成的

import pygame
import pickle
class Tileset:
    def __init__(self, location):
        pass

class Tilemap:
    def __init__(self):
        pass

class Collisionmap(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()

class Player(pygame.sprite.Sprite):
    def __init__(self, spritesheet):
        super().__init__()
        self.spritesheet = pygame.image.load(spritesheet)
        self.x = 0
        self.y = 0
    def draw(self, surface):
        surface.blit(self.spritesheet, (self.x, self.y))

class Mob(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()

class Camera:
    def __init__(self):
        self.x = 0
        self.y = 0
        self.width = 100
        self.height = 100
        self.surface = pygame.Surface((self.width, self.height))
    def moveToSprite(self, sprite):
        self.x = sprite.rect.centerx - WIDTH // 2
        self.y = sprite.rect.centery - HEIGHT // 2
    def update(self, world):
        self.surface = world.subsurface((self.x, self.y, self.width, self.height))

class Level:
    def __init__(self, terrarin, collision, mobs):
        self.terrain = terrain
        self.collision = collision
        self.mobs = mobs

class Game:
    def __init__(self):
        pygame.init()
        self.DISPLAYSURF = pygame.display.set_mode((0, 0))
        self.mainCamera = Camera()
        self.mainCamera.width = self.DISPLAYSURF.get_width()
        self.mainCamera.height = self.DISPLAYSURF.get_height()
        self.otherCameras = []
        self.worldSurface = pygame.Surface((10000, 10000))
        self.player = Player("marioSS.jpg")
        self.otherCameras.append(Camera())
        self.run()
    def run(self):
        while True:
            for event in pygame.event.get():
                pass
            self.earlyUpdate()
            self.update()
            self.lateUpdate()
            self.graphicsUpdate()
    def update(self):
        pass
    def earlyUpdate(self):
        pass
    def lateUpdate(self):
        pass
    def graphicsUpdate(self):
        for each in self.otherCameras:
            each.update(self.worldSurface)
        self.player.draw(self.worldSurface)
        self.otherCameras[0].surface.unlock()
        self.worldSurface.unlock()
        self.worldSurface.blit(self.otherCameras[0].surface, (100, 100)) ##Error here
        self.mainCamera.update(self.worldSurface)
        self.DISPLAYSURF.blit(self.mainCamera.surface, (0, 0))
        pygame.display.update()

x = Game()


问题使
Camera.update()

它不会将数据从
world
复制到
surface
,但会分配对原始
world
的访问权限。然后你有:
camera.surface
保持对
world
的访问,并且
blit
尝试从
camera.surface
复制到
world
——所以最后它尝试从
world
复制到
world
。也许它能锁住它

但是如果在
Camera.update()
中使用
.copy()

或者干脆

self.surface.blit(world.subsurface((self.x, self.y, self.width, self.height)), (0,0))
然后它就起作用了


文件:

地下(直射)->表面

返回与新父曲面共享像素的新曲面。


始终将完整的错误消息(从单词“Traceback”开始)作为文本(而不是屏幕截图)进行讨论(不是评论)。还有其他有用的信息。
self.surface.blit(world.subsurface((self.x, self.y, self.width, self.height)), (0,0))