Camera & Cinematics
The new camera and preloading APIs allow you to create dynamic cutscenes, boss reveals, and specific map perspectives smoothly.
Life Hack: The Cinematic Reveal
When executing a cutscene, asset loading times can ruin the immersion. By using player.preloadasset(...) before transitioning the camera, you guarantee that sounds, animations, or images are ready the exact millisecond they are needed.
The following example combines setcamerazoom, preloading, audio, and the sleep function (which pauses the script context for that player) to create a dramatic sequence.
/**
* Triggers a boss reveal cutscene for the player.
* Make sure to run this on the client-side context (e.g., inside onClientEVENT).
*/
function triggerBossCinematic(player) {
// 1. Preload the sound so there's no delay when playing it
player.preloadasset(['boss_roar.wav', 'boss_spawn.bani']);
// 2. Lock camera to specific map coordinates and zoom in smoothly
player.setcamerazoom({
x: 50, // Tile X coordinate of the boss
y: 60, // Tile Y coordinate of the boss
zoom: 2.0, // 2x zoom level
speed: 0.02, // Slow, dramatic pan speed
instant: false, // Smooth transition
blend: 1.0 // 1 second smooth position blend
});
// 3. Play the preloaded sound immediately
player.play('boss_roar.wav');
// 4. Restore camera to normally track the player again after 3 seconds
this.scheduleevent(3, 'resetCamera', player);
}
function onResetCamera(player) {
player.resetcamerazoom();
player.showmessage('The boss has appeared!');
}
Static vs. Zoom Modes
Remember that setcamerazoom has two primary modes based on the parameters you provide:
- Static Mode: Provide
xandy. The camera stops tracking the player and locks to the coordinates. - Zoom Mode: Omit
xandy. The camera continues tracking the player normally, but smoothly scales the zoom level.