The camara service
Reference for the camara service. Each player's camera: the view (third person, first person, 2D, isometric), distance, tilt, what it follows and temporary shots.
DescribesFormato 1, API 1 For those who write code This page is generated from the SDK sources.
On this page
Each player has their own camera. By default: third person, orbital, it settles behind the avatar by itself and moves closer if a piece blocks the view.
The types used in the signatures (Vec3, Texto, the selector) are in the API reference.
Functions and properties of camara#
camara.fijar#
camara.fijar(ajustes: {
distancia?: number; // 2 to 60; 10 by default
inclinacion?: number; // degrees above the horizon, -10 to 89 (89: seen from above); 22 by default
giro?: number; // degrees; 0 looks toward +Z. Places the camera there once
libre?: boolean; // false: the player cannot rotate it
giroAutomatico?: boolean; // false: it does not settle behind the avatar by itself
evitarObstaculos?: boolean; // false: it does not move closer when something blocks the view
campo?: number; // field of view, 30 to 100
seguir?: Jugador | Actor | Pieza | Vec3 | null; // what it follows; null goes back to the player
}, para?: Jugador): voidChanges the camera settings of one player (or of everyone). Only what you pass changes.
From docs/EJEMPLOS.md, «camara»:
// Puzle visto desde arriba: camara fija, el jugador no la gira.
camara.fijar({ inclinacion: 70, distancia: 24, giro: 0, libre: false });camara.toma#
camara.toma(def: { desde: Vec3; hacia: Vec3 | Jugador | Actor | Pieza; duracion: number; campo?: number }, para?: Jugador): voidA temporary shot: the camera goes to desde, looks at hacia for duracion seconds and returns on its own.
From docs/EJEMPLOS.md, «camara»:
// Toma de dos segundos al abrirse la puerta; despues vuelve sola.
mundo.alTocar('palanca', () => camara.toma({ desde: [0, 6, -8], hacia: mundo.pieza('puerta'), duracion: 2 }));camara.restablecer#
camara.restablecer(para?: Jugador): voidGoes back to the default camera.
camara.vista#
camara.vista(def: VistaDef | TipoVista | null, opciones?: { transicion?: number }, para?: Jugador): voidChanges the type of view and of control for one player (or for everyone): camara.vista('lateral') or camara.vista({ tipo: 'isometrica', zoom: 14 }). The camera moves to the new view in transicion seconds (0.6 by default). With null the view of the scene comes back.
From games/valle-abierto/scripts/principal.ts:
camara.vista(e.tercera ? { tipo: 'tercera-persona', distancia: 7 } : 'primera-persona', { transicion: 0.4 }, j);Behavior notes#
- A fixed raised view for a puzzle:
camara.fijar({ inclinacion: 70, distancia: 24, giro: 0, libre: false }). camara.tomais temporary: the camera goes todesde, looks athaciaforduracionseconds and returns on its own.- Controls stay relative to the camera: with a fixed camera, "forward" is always the same direction.
Complete examples#
Complete scripts from docs/EJEMPLOS.md. Each one assumes a scene containing what it names, and the text keys (interfaz.t('...')) must exist in textos of juego.json.
camara#
import { camara, juego, jugadores, mundo } from '@greengames/sdk';
juego.alIniciar(() => {
// Puzle visto desde arriba: camara fija, el jugador no la gira.
camara.fijar({ inclinacion: 70, distancia: 24, giro: 0, libre: false });
// Toma de dos segundos al abrirse la puerta; despues vuelve sola.
mundo.alTocar('palanca', () => camara.toma({ desde: [0, 6, -8], hacia: mundo.pieza('puerta'), duracion: 2 }));
// Repeticion de un gol: todos miran la pelota tres segundos y vuelven a su avatar.
mundo.alChocar('pelota', (pelota, otra) => {
if (!otra.tiene('arco')) return;
camara.fijar({ seguir: pelota, distancia: 6 });
for (const j of jugadores.todos()) j.congelado = true;
});
});Next#
- API reference: the eleven services and the common types.
- Scripts: the rules of a script and how it runs inside the room.