如何在pygame中创建4向拆分屏幕 [英] how to create a 4-way split screen in pygame

查看:235
本文介绍了如何在pygame中创建4向拆分屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我必须使用pygame创建4向拆分屏幕。在此屏幕上,我必须在每个屏幕上绘制相同的图像,只是图像的视图不同。我只是不知道如何使用pygame创建此4向拆分屏幕。

I have a project where i have to create a 4 way split screen using pygame. On this screen i have to draw the same image on each of the screen just have different view of the image. I just can not figure out how to create this 4 way split screen using pygame.

我需要像上面那样划分屏幕,以便可以在每个部分上绘制点。

I need my screen to be divided like above so i can draw my points onto each section.

我一直在四处张望,我找不到这样的东西,所以任何帮助都会很棒
谢谢

I have been looking around and I can not find anything like this so any help would be great thanks

推荐答案

除了您要渲染到显示器上的表面(可能称为 screen 之类的东西)之外,您还应该创建另一个表面被吸引。然后,您可以为屏幕的每个象限使用 Rect 对象,该对象将代表摄像机(假设每个象限不一定需要显示完全相同的图像)。退回到屏幕时,使用每个摄像机 Rect 对象选择要绘制到的游戏空间的一部分一个特定的象限。

In addition to the surface you have that gets rendered to the display, likely called something like screen, you should create another surface which all of the "action" gets drawn to. You can then use a Rect object for each quadrant of the screen which will represent the "camera" (assuming each quadrant doesn't necessarily need to show exactly the same image). When you draw back to screen, you use each camera Rect object to select a portion of the game space to draw to a specific quadrant.

# 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)

在每个上更新后,您将使用这些相机对象将画布的各个部分变回到屏幕表面。

On each update, you would then use these "camera" objects to blit various portions of the canvas back to the screen surface.

# 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()

这篇关于如何在pygame中创建4向拆分屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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