如何使 Pygame Zero 窗口全屏? [英] How to make a Pygame Zero window full screen?

查看:350
本文介绍了如何使 Pygame Zero 窗口全屏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用易于使用的 Python 库 pgzero(内部使用 pygame)来编写游戏.

I am using the easy-to-use Python library pgzero (which uses pygame internally) for programming games.

如何让游戏窗口全屏显示?

How can I make the game window full screen?

import pgzrun

TITLE = "Hello World"

WIDTH  = 800
HEIGHT = 600

pgzrun.go()

注意:我正在使用运行时帮助程序库 pgzrun 使游戏无需操作系统 shell 命令即可执行...它隐式导入 pgzero 库...

Note: I am using the runtime helper lib pgzrun to make the game executable without an OS shell command... It implicitly imports the pgzero lib...

pgzero 在内部使用 pygame,也许使用 pygame API 更改了窗口模式...

pgzero uses pygame internally, perhaps there is a change the window mode using the pygame API...

推荐答案

您可以通过 screen.surface 并且您可以在 draw() 来自 pygame.display.set_mode().例如:

You can access the pygame surface which represents the game screen by screen.surface and you can change the surface in draw() by pygame.display.set_mode(). e.g.:

import pgzrun
import pygame

TITLE = "Hello World"

WIDTH  = 800
HEIGHT = 600

def draw():
    screen.surface = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN)

pgzrun.go()

或者在按下f键时切换到全屏分别在key down事件中按下w键返回窗口模式(on_key_down):

Or switch to fullscreen when the f key is pressed respectively return to window mode when the w key is pressed in the key down event (on_key_down):

import pgzrun
import pygame

TITLE = "Hello World"

WIDTH  = 800
HEIGHT = 600

def on_key_down(key):
    if key == keys.F:
        screen.surface = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN)
    elif key == keys.W:
        screen.surface = pygame.display.set_mode((WIDTH, HEIGHT))

pgzrun.go()

这篇关于如何使 Pygame Zero 窗口全屏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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