Skip to content

@carrot/engine-vue ​

tsvue

Vue 3 composables for integrating the Carrot WebGL engine into Vue applications.

Usage ​

ts
import { useEngine, useScene, useInput } from '@carrot/engine-vue';
vue
<script setup lang="ts">
import { ref } from 'vue';
import { useEngine, useScene, useInput } from '@carrot/engine-vue';

const canvasRef = ref<HTMLCanvasElement>();
const { game, engine, fps, running, start, stop } = useEngine({ canvas: canvasRef });
const { scene, entities, switchTo } = useScene(game);
const { isGamepadActive, activeDevice } = useInput(engine);
</script>

<template>
  <canvas ref="canvasRef" />
</template>

Contents ​

Composables: useEngine · useScene · useInput

Types: UseEngineOptions · UseEngineReturn · UseSceneReturn · UseInputReturn

ComposablePurpose
useEngine(options)Create and manage an engine instance bound to a canvas ref
useScene(game)Reactive access to the current scene and its entities
useInput(engine)Track active input device and gamepad state

Build ​

bash
npm run build

Requires vue@^3.4.0 as a peer dependency.


@carrot/engine-vue - Contents ​

Import: import { ... } from '@carrot/engine-vue';

Composables ​

useEngine · useScene · useInput


useEngine ​

ts
function useEngine(options: UseEngineOptions): UseEngineReturn;

Options - UseEngineOptions

PropertyTypeDefaultDescription
canvasRef<HTMLCanvasElement | undefined>-Required. Ref to the canvas element
logLogundefinedOptional log instance
aspectRatioAspectRatioundefinedOptional aspect ratio enforcement
assetBasePathstring'/assets/'Asset base path
sceneSceneundefinedInitial scene to start with
autoStartbooleantrueAuto-start the engine on mount

Return - UseEngineReturn

PropertyTypeDescription
gameShallowRef<Game | undefined>The Game instance
engineShallowRef<Engine | undefined>The Engine instance
fpsRef<number>Reactive FPS counter (updated every 500ms)
runningRef<boolean>Whether the engine is currently running
start(scene?: Scene) => Promise<void>Start the engine with an optional scene
stop() => voidStop the engine

useScene ​

ts
function useScene(game: ShallowRef<Game | undefined>): UseSceneReturn;

Return - UseSceneReturn

PropertyTypeDescription
sceneShallowRef<Scene | undefined>The current active scene
entitiesShallowRef<readonly Entity[]>Entities in the current scene
switchTo(scene: Scene) => Promise<void>Switch to a different scene

useInput ​

ts
function useInput(engine: ShallowRef<Engine | undefined>): UseInputReturn;

Return - UseInputReturn

PropertyTypeDescription
inputShallowRef<Input | undefined>The Input system instance
isGamepadActiveRef<boolean>Whether the active input device is a gamepad
activeDeviceRef<string>Name of the active input device category (e.g. 'Keyboard', 'Gamepad')

Types ​

UseEngineOptions · UseEngineReturn · UseSceneReturn · UseInputReturn

Carrot