A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
/**
* @file sceneTransition.ts
* @brief Convenience wrapper for scene transitions
*/
import type { App } from '../app/app';
import type { Color } from '../types';
import { SceneManager, SceneManagerState } from './sceneManager';
/** A cross-scene fade: how long, and what colour it passes through.
* @beta */
export interface TransitionConfig {
duration: number;
type: 'fade';
color?: Color;
}
/**
* Pass the App from host code, or the `Res(SceneManager)` state from inside a
* system.
*
* @beta
*/
export async function transitionTo(
host: App | SceneManagerState,
targetScene: string,
config: TransitionConfig,
): Promise<void> {
const manager = host instanceof SceneManagerState ? host : host.getResource(SceneManager);
await manager.switchTo(targetScene, {
transition: config.type,
duration: config.duration,
color: config.color,
});
}