简体   繁体   English

Pyglet:全屏显示时如何更改分辨率?

[英]Pyglet: How to change resolution when you go fullscreen?

I'm using Pyglet and I have a little that includes an object moving over a background. 我正在使用Pyglet,但有一点点,其中包括一个在背景上移动的对象。 Both of them are represented by images (png and jpg). 它们都由图像(png和jpg)表示。

I've created a non-fullscreen window with size 800x600 and it works fine, but when I toggle to fullscreen... background and object have the same size as before and the rest of the screen is filled with black (empty color). 我创建了一个非全屏窗口,大小为800x600,它可以正常工作,但是当我切换到全屏时...背景和对象的大小与以前相同,并且屏幕的其余部分填充为黑色(空色)。

What I want to do is to "scale" the images or change the resolution when I toggle fullscreen mode. 我想要做的是在切换全屏模式时“缩放”图像或更改分辨率。

I've read the documentation, but I can't find the answer to this. 我已经阅读了文档,但是找不到答案。

I know that with Pygame, this problem solves itself automatically (if you change the window size, everything rescales automatically)... but how do you do this with pyglet? 我知道使用Pygame,此问题会自动解决(如果您更改窗口大小,一切都会自动缩放)...但是如何使用pyglet做到这一点?

This is my relevant code: 这是我的相关代码:

import pyglet

WIDTH = 800
HEIGHT = 600
working_dir = '/where/i/have/my/images/'

window = pyglet.window.Window(WIDTH, HEIGHT)

background = pyglet.image.load(working_dir + 'background.jpg')
flying_thing = pyglet.image.load(working_dir + 'flying_thing.png')

@window.event
def on_draw():
    window.clear()
    background.blit(0, 0)
    flying_thing.blit(WIDTH // 2, HEIGHT // 2)

@window.event
def on_key_press(symbol, modifiers):
    if symbol == pyglet.window.key.SPACE:
        window.set_fullscreen(not window.fullscreen)

pyglet.app.run()

You can try this code changing working_dir, background.jpg and flying_thing.png to a working directory of yours and two images in it. 您可以尝试将此代码将working_dir,background.jpg和flying_thing.png更改为您的工作目录,并在其中包含两个图像。

I didn't tried, but from pyglet docs , blit supports width and height. 我没有尝试过,但是从pyglet docs开始blit支持宽度和高度。 Its signature is 它的签名是

blit(self, x, y, z=0, width=None, height=None)

Have you tried using 您是否尝试过使用

background.blit(width=window.width, height=windows.height)

instead? 代替? (I'm not sure the window.width changes on full_screen, let's see...). (我不确定window.width在full_screen上是否发生变化,让我们看看...)。

This answer can also be relevant to your question: https://stackoverflow.com/a/11183462/931303 . 此答案也可能与您的问题有关: https : //stackoverflow.com/a/11183462/931303

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM