Dividing Resolution by half?

Alright, sorry if this is the wrong place as it’s my second time posting on this website. I would like to make a script in python that would allow me to get the screens current resolution in a game, and divide that by half. I had originally thought of using bge.render.getWindowHeight() and assigning the return to a variable and then using that variable in bge.render.setWindowSize(width, height) but it didn’t seem to work. Any tips?

Managed to get it working. It will only work when you run in stand alone player!

You will need a sensor named “Keyboard” and a property called “small”

Be sure to toggle the console which will give you any errors in a some what human readable format (Window -> Toggle System Console).

The type casting to int is crucial. It wont work if you don’t cast to an int.

from bge import logic
from bge import render

cont = logic.getCurrentController()
own = cont.owner

if cont.sensors['Keyboard'].positive:
    if own['small'] == False:
        new_size = int(render.getWindowHeight()/2)
        print("Requested window size: " + str(new_size))
        render.setWindowSize(new_size, new_size)
        own['small'] = True
        render.setWindowSize(500, 500)
        own['small'] = False

Blend file attached.

Works a charm :slight_smile:


WindowResize.blend (454 KB)

Oh wow, thanks! I’ll have to try that out now. I think I was missing int in my original code.