The Scene object represents the whole graphics subsystem in wasabi2d. Scenes manage a collection of graphical primitives within a number of layers.
Create a scene with:
from wasabi2d import Scene scene = Scene(width, height)
Get/set the background color of the entire scene as an RGB triple. (1, 1, 1) is white and (0, 0, 0) is black.
You can also assign color names or HTML color codes (but the value is stored and returned as a tuple).
The collection of layers that will be drawn. Layers are created on access and do not need to be explicitly declared.
Layers are drawn from back to front - lowest layer number to highest.
Get/set the caption for the window.
(read-only) The width of the scene in pixels.
(read-only) The height of the scene in pixels.
There’s also an off-screen version, which will mainly be useful for testing and screenshotting:
New in version 1.4.0.
pixel_art=True in the scene constructor turns off bilinear
interpolation of textures. This means that pixel edges will be clearly
visible and pixels will appear square, but may be rotated.
This is slightly different to Scene scaling, which applies filtering at a higher level. In particular, scene scaling affects Post-processing effects while pixel_art mode does not. The two options can be used together or not.
Here are some examples of how sprites appear when zoomed. These differences will be less visible without magnification.
This will currently mess up things like mouse events due to the mouse pointer not matching the position of your cursor. See this.
Scene scaling allows the wasabi2d scene to be scaled independently of the final window size. Two uses of this are:
Supporting high dpi/retina displays with practically the same performance as standard displays (but reduced quality).
Retro games, in order to draw everything pixellated.
The scene will aways have the requested dimensions, but the window will usually be a bigger size; the biggest integer multiple that fits your screen. The scaler in use determines how the scene is upscaled to the window.
To use this, set
scaler to one of:
'nearest'- nearest pixel; creates a pixellated appearance. Ideal for retro games.
'linear'- linearly interpolate between pixel values.
For example, to create a retro game with a 200x100 pixel screen (very blocky
indeed), create a scene with a small viewport size, but set
scene = Scene( width=200, height=120, scaler=True )
This will create a scene that is logically 200x120:
All rendering will take place on a 200x120 frame buffer.
Mouse coordinates will be correctly translated to scene coordinates, eg. the bottom right corner is
Unusually for an OpenGL-based game engine, wasabi2d uses Pygame’s coordinate system where the top of the screen has coordinate 0 and coordinates increase downwards.
This allows easier porting of Pygame Zero games.
By default distances are measured in screen pixels.
The camera for the scene is
Get/set the center position of the camera, as a 2D vector/pair of floats.
Initially, this is
(scene.width / 2, scene.height / 2).
Screenshot and Video Recording¶
Games automatically have access to screenshot and video recording capabilities.
This is hard coded to:
F12- take a screenshot, named with an automatic filename.
Shift-F12- start/stop recording a video, named with an automatic filename.
New in version 1.3.0: Hard-coded screenshot/video capture to F12.
Recording video requires
ffmpeg to be installed and on the
As well as this, you can use these features programmatically: