Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在pygame中创建4向分割屏幕_Python 3.x_Drawing_Pygame - Fatal编程技术网

Python 3.x 如何在pygame中创建4向分割屏幕

Python 3.x 如何在pygame中创建4向分割屏幕,python-3.x,drawing,pygame,Python 3.x,Drawing,Pygame,我有一个项目,我必须创建一个4路分裂屏幕使用pygame。在这个屏幕上,我必须在每个屏幕上绘制相同的图像,只是图像的视图不同。我只是想不出如何使用pygame创建这个4向分割屏幕 我需要我的屏幕像上面一样划分,这样我就可以把我的点到每个部分 我一直在四处寻找,我找不到像这样的东西,所以任何帮助都将是巨大的 谢谢没有分割屏幕的功能。但您可以直接在屏幕上绘制4个视图,也可以在屏幕上绘制4个曲面(),而不是blit曲面。除了渲染到显示器上的曲面(可能称为屏幕)之外,您还应该创建另一个曲面,将所有“动

我有一个项目,我必须创建一个4路分裂屏幕使用pygame。在这个屏幕上,我必须在每个屏幕上绘制相同的图像,只是图像的视图不同。我只是想不出如何使用pygame创建这个4向分割屏幕

我需要我的屏幕像上面一样划分,这样我就可以把我的点到每个部分

我一直在四处寻找,我找不到像这样的东西,所以任何帮助都将是巨大的
谢谢

没有分割屏幕的功能。但您可以直接在屏幕上绘制4个视图,也可以在屏幕上绘制4个曲面(),而不是blit曲面。

除了渲染到显示器上的曲面(可能称为
屏幕
)之外,您还应该创建另一个曲面,将所有“动作”都绘制到该曲面上。然后,您可以为屏幕的每个象限使用
Rect
对象,该对象将表示“摄影机”(假设每个象限不一定需要显示完全相同的图像)。当你回到
屏幕
时,你可以使用每个摄像头
Rect
对象来选择游戏空间的一部分以绘制到特定的象限

# canvas will be a surface that captures the entirety of the "action"
canvas = pygame.Surface((800, 600))
# the following are your "camera" objects
# right now they are taking up discrete and even portions of the canvas,
# but the idea is that they can move and possibly cover overlapping sections
# of the canvas
p1_camera = pygame.Rect(0,0,400,300)
p2_camera = pygame.Rect(400,0,400,300)
p3_camera = pygame.Rect(0,300,400,300)
p4_camera = pygame.Rect(400,300,400,300)
在每次更新时,您都会使用这些“摄影机”对象将画布的各个部分快速返回到
屏幕
表面

# draw player 1's view  to the top left corner
screen.blit(canvas, (0,0), p1_camera)
# player 2's view is in the top right corner
screen.blit(canvas, (400, 0), p2_camera)
# player 3's view is in the bottom left corner
screen.blit(canvas, (0, 300), p3_camera)
# player 4's view is in the bottom right corner
screen.blit(canvas, (400, 300), p4_camera)

# then you update the display
# this can be done with either display.flip() or display.update(), the
# uses of each are beyond this question
display.flip()

由于您正在寻找将屏幕分成4个部分并在其上绘制一些点的方法,为了方便起见,我建议创建原始“画布”图像的4个
次表面
。
这些表面将作为你的球员(分裂屏幕)画布,可以很容易地修改。
这将允许使用标准化坐标进行特定于玩家的绘图

假设您设置了
屏幕
曲面

# Image(Surface) which will be refrenced
canvas = pygame.Surface((800, 600))

# Camera rectangles for sections of  the canvas
p1_camera = pygame.Rect(0,0,400,300)
p2_camera = pygame.Rect(400,0,400,300)
p3_camera = pygame.Rect(0,300,400,300)
p4_camera = pygame.Rect(400,300,400,300)

# subsurfaces of canvas
# Note that subx needs refreshing when px_camera changes.
sub1 = canvas.subsurface(p1_camera)
sub2 = canvas.subsurface(p2_camera)
sub3 = canvas.subsurface(p3_camera)
sub4 = canvas.subsurface(p4_camera)
现在用这些标准化坐标在任何子曲面上绘制

# Drawing a line on each split "screen" 
pygame.draw.line(sub2, (255,255,255), (0,0), (0,300), 10)
pygame.draw.line(sub4, (255,255,255), (0,0), (0,300), 10)
pygame.draw.line(sub3, (255,255,255), (0,0), (400,0), 10)
pygame.draw.line(sub4, (255,255,255), (0,0), (400,0), 10)

# draw player 1's view  to the top left corner
screen.blit(sub1, (0,0))
# player 2's view is in the top right corner
screen.blit(sub2, (400, 0))
# player 3's view is in the bottom left corner
screen.blit(sub3, (0, 300))
# player 4's view is in the bottom right corner
screen.blit(sub4, (400, 300))

# Update the screen
pygame.display.update()

请注意,对次表面像素的修改也会影响画布。我建议您阅读上的完整文档。

我认为您必须自己管理所有这些。很可能不会有任何这样的功能。您可以尝试通过绘制所有框来划分屏幕,并保持必要的全局屏幕值,以便在所有屏幕中绘制到相似的位置。感谢alot Haz,这正是我一直在寻找的,它工作得很好