Question

I'm using Pyglet and I have a little that includes an object moving over a background. Both of them are represented by images (png and 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).

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?

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.

Was it helpful?

Solution

I didn't tried, but from pyglet docs, blit supports width and height. 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...).

This answer can also be relevant to your question: https://stackoverflow.com/a/11183462/931303.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top