高效地将Pygamescreens加载到2D列表

时间:2018-05-28 18:26:36

标签: python pygame

我正在寻找一种快速的方法:

def load(screen):
    x, y = (screen.get_size()[0], screen.get_size()[1])
    list = []
    out = []
    for pln in range(x):
        for prn in range(y):
            liste.append(screen.get_at([pln, prn]))
        out.append(copy.deepcopy(list))
        list = []
    print ("finish")
    #print(len(out))
    return copy.deepcopy((out))

屏幕是使用pygame.display.set_mode(*size*)

创建的对象

在这里,我尝试在2d列表中写入get_at的颜色。是否有Pygame的内置函数来执行此操作?我的意思是,这段代码很慢......

1 个答案:

答案 0 :(得分:0)

You can almost triple the speed by using pygame.surfarray.

But I don't thing you actually want to have a list of the pixels. Please post a new question with you underling problem, as @hop suggested.

def load(screen):
    return pygame.surfarray.pixels2d(screen).tolist()