在 pygame 中创建多个屏幕 [英] Creating multiple screens in pygame

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

问题描述

有没有办法在 Pygame 中创建多个屏幕而无需每次都重新绘制到屏幕上.例如,如果我们想创建一个启动画面,那么一个带有按钮的主菜单.单击开始游戏"按钮后,它将进入一个新屏幕,即实际游戏.我的意思是类似于 Visual Studio 上的表单"或 Android 上的 Activites.

Is there any way way to create multiple screens in Pygame without redrawing to the screen every time. For example, if we want to create a splash screen, then a main menu with buttons. On clicking the 'Start Game' button, it would go to a new screen which is the actual game. What I mean is anything similar to the 'Form' on Visual Studio or the Activites on Android.

推荐答案

取决于你的意思.

如果你的意思是同时创建多个窗口,不,你不能这样做——这是 SDL 的一个限制(尽管你可以通过使用多处理(而不是多线程)来伪造它).

If you mean making multiple windows at the same time, no, you can't do that--it's a limitation of SDL (although you CAN fake it by using multiprocessing (not multithreading)).

如果你的意思是改变一个屏幕,是的,你可以通过多次调用 pygame.display.set_mode(...) 来做到这一点.您可以更改分辨率、参数等.如果您正在做 OpenGL 的事情,那也会重新制作上下文.

If you mean changing one screen around, yes, you can do that, with multiple calls to pygame.display.set_mode(...). You can change the resolution, arguments, etc. If you're doing OpenGL stuff, that will remake the context too.

当然,如果您只是想在同一个窗口中绘制不同的东西!这就是 PyGame 的重点.

If you just mean drawing different things to the same window, of course! That's sorta the point of PyGame.

除此之外,你必须澄清.

Other than that, you'll have to clarify.

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

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