Bacon games have a single window within which they do all their drawing. This window exists even if the game is fullscreen. To customize the window, set properties on the bacon.window object, which is the only instance of the Window class.
At the very least you should set the size of the window your game should run in before calling run():
bacon.window.width = 640
bacon.window.height = 480
By default the window will not be resizable by the user (but your code can modfy the window size at any time). To allow the user to resize the window, set Window.resizable to True.
Use the Window.fullscreen property to switch in and out of fullscreen mode:
.. note:: TODO fullscreen example
Usually games are designed for a specific target resolution, and it is difficult to adapt to a larger or smaller window. Making the window non-resizable will certainly fix the window size to the desired dimensions, however this doesn’t help if you want to also support fullscreen, since different computers will have different screen resolutions.
The window.target property can be used in this situation. Set to an image of the desired dimensions, this image will be used as the default render target, and will be drawn into the window with scaling and letterboxing as appropriate.
The following example is a game designed for exactly 512x512 resolution, but the window is both resizable and able to be set to fullscreen. Note the atlas=0 argument passed to the offscreen image constructor: this is necessary as the target image cannot be used if it shares a texture atlas with the images and fonts you will be drawing.
import bacon
bacon.window.resizable = True
bacon.window.width = 512
bacon.window.height = 512
bacon.window.target = bacon.Image(width=512, height=512, atlas=0)
font = bacon.Font(None, 16)
class Game(bacon.Game):
def on_tick(self):
bacon.clear(0.2, 0.2, 0.2, 1.0)
bacon.draw_string(font,
'Window target dimensions are fixed to 512x512 but window is resizable; press "f" for fullscreen',
x=0, y=0,
width=512, height=512,
align=bacon.Alignment.center,
vertical_align=bacon.VerticalAlignment.center)
def on_key(self, key, pressed):
if key == bacon.Keys.f and pressed:
bacon.window.fullscreen = not bacon.window.fullscreen
bacon.run(Game())
If your game is designed with a “pixel-art” style, consider creating the target with sample_nearest=True and content_scale=1 arguments in the Image constructor to preserve sharp edges between pixels.