# SceneScript Event resizeScreen
This function will be called every time the wallpaper resizes because of a change to the current screen resolution. It is useful if you want to adjust wallpaper elements when the user changes their screen resolution or orientation.
The parameter size is a Vec2 object that contains the new resolution, where size.x is the new width and size.y is the new height.
export function resizeScreen(size: Vec2) {
}
Usually, it makes sense to combine it with the init event if your resizing logic is entirely happening in SceneScript.
# Sample Usage
In the example below, we want a layer to change its scale depending on the screen resolution. An example use-case for this would be to make text appear slightly larger on lower resolution screens to make it more readable but you can adjust this logic for a wide range of purposes.
Notice how the resizeScreen event is used in combination with the init event so that the logic is applied when the wallpaper loads and then the user changes the resolution. Our actual custom logic (that you would need to replace or adjust to your needs) sits in a custom function called updateResolution.
'use strict';
/**
* Called every time the wallpaper resizes due to a resolution change.
* * @param {Vec2} size The new screen resolution in pixels.
*/
export function resizeScreen(size) {
thisLayer.scale = updateResolution(size);
}
/**
* Called once after the object is created.
*/
export function init() {
// resizeScreen is not called on startup, so we manually trigger the resolution logic once
thisLayer.scale = updateResolution(engine.screenResolution);
}
/**
* Custom function to handle resolution-dependent logic.
* By keeping this separate, we avoid duplicating code in init() and resizeScreen().
* * @param {Vec2} size The screen resolution in pixels.
*/
function updateResolution(size) {
let scaleFactor;
// Determine which axis to check based on the monitor's orientation.
// If landscape, evaluate the width (x). If portrait, evaluate the height (y).
let primaryDimension = engine.isLandscape() ? size.x : size.y;
// Check the primary dimension to determine the resolution tier
if (primaryDimension < 1920) {
// Under 1080p (e.g., small laptops or small vertical screens)
scaleFactor = 1.3;
} else if (primaryDimension < 2560) {
// 1080p tier (e.g., 1920x1080 or 1080x1920 portrait)
scaleFactor = 1.0;
} else if (primaryDimension < 3840) {
// 1440p tier / ultrawides
scaleFactor = 0.8;
} else {
// 4K tier and above
scaleFactor = 0.6;
}
return new Vec3(scaleFactor, scaleFactor, scaleFactor);
}