Skip to content
Docs

The reloj service

Reference for the reloj service. Match time and timers.

DescribesFormato 1, API 1 For those who write code This page is generated from the SDK sources.

On this page

Match time and timers.

The types used in the signatures (Vec3, Texto, the selector) are in the API reference.

Functions and properties of reloj#

PropertyTypeDescription
reloj.ahoranumberSimulation seconds since the match started. It stops while paused.
reloj.cuadronumberFrame number (60 per second).

reloj.despues#

ts
reloj.despues(segundos: number, fn: () => void): number

Calls fn once, after segundos. Returns an id for canceling.

From docs/EJEMPLOS.md, «reloj»:

ts
reloj.despues(3, () => interfaz.mensaje(interfaz.t('ya')));

reloj.cada#

ts
reloj.cada(segundos: number, fn: () => void): number

Calls fn every segundos. Returns an id for canceling.

From docs/EJEMPLOS.md, «mundo: luces, ambiente y zonas creadas por el script»:

ts
reloj.cada(0.5, () => (faro.encendida = !faro.encendida));

reloj.cancelar#

ts
reloj.cancelar(id: number): void

Cancels a timer. Takes the id returned by reloj.despues or reloj.cada.

From docs/EJEMPLOS.md, «reloj»:

ts
mundo.alEntrar('meta', () => reloj.cancelar(ciclo));

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.

reloj#

scripts/principal.ts
import { interfaz, juego, mundo, reloj } from '@greengames/sdk';

juego.alIniciar(() => {
  reloj.despues(3, () => interfaz.mensaje(interfaz.t('ya')));
  const ciclo = reloj.cada(2, () => {
    const puerta = mundo.pieza('puerta');
    puerta.solida = !puerta.solida;
    puerta.visible = puerta.solida;
  });
  mundo.alEntrar('meta', () => reloj.cancelar(ciclo));
});

Next#