Estudio de Phaser.js

Juegos ⭐ 34k stars
Marco de juegos HTML5 2D/3D con WebGL, Canvas y físicas integradas.

🤖 Skill de implementación: frontend-desarrollo (regla: solo catálogo de las 66 · versiones por ERR/MEJ)

1 · Características

2 · Casos de uso

3 · Script minimalista

Instalación: npm i phaser (o CDN)

new Phaser.Game({ type: Phaser.AUTO, width: 400, height: 300,
  scene: { create() { this.add.text(20, 20, 'Hola Phaser'); } } });

4 · Casos de uso (implementación real)

Dos casos de uso comunes implementados con esta librería.

1. Movimiento con teclas

Un sprite se mueve con las flechas.

new Phaser.Game({
  type: Phaser.AUTO, width: 400, height: 300,
  scene: {
    create() {
      this.jug = this.add.rectangle(200, 150, 30, 30, 0xff6600);
      this.cursors = this.input.keyboard.createCursorKeys();
    },
    update() {
      const p = this.jug; const c = this.cursors;
      if (c.left.isDown) p.x -= 3; if (c.right.isDown) p.x += 3;
      if (c.up.isDown) p.y -= 3; if (c.down.isDown) p.y += 3;
    },
  },
});
🔁 Cómo funciona: `createCursorKeys` captura las flechas y `update` (por frame) aplica el movimiento.

2. Colisiones + marcador

Cuenta cuántas monedas recoge el jugador.

const game = new Phaser.Game({
  type: Phaser.AUTO, width: 400, height: 300,
  scene: {
    create() {
      this.puntos = 0;
      this.jug = this.add.rectangle(20, 150, 30, 30, 0x3399ff);
      this.moneda = this.add.circle(350, 150, 12, 0xffd700);
      this.txt = this.add.text(10, 10, 'Puntos: 0');
    },
    update() {
      const d = Phaser.Math.Distance.Between(this.jug.x, this.jug.y, this.moneda.x, this.moneda.y);
      if (d < 30) { this.puntos++; this.txt.setText('Puntos: ' + this.puntos); this.moneda.setVisible(false); }
    },
  },
});
🔁 Cómo funciona: Se calcula la distancia jugador-moneda por frame; al acercarse suma puntos y oculta la moneda.

5 · Referencia

CategoríaJuegos
Stars (GitHub)⭐ 34k
Sitio oficialhttps://phaser.io/
GitHubhttps://github.com/photonstorm/phaser
Instalaciónnpm i phaser (o CDN)
RelacionadasBabylon.js · Pixi.js · CreateJS
📦 Regla de librerías (local primero): revisar C:\Users\TUF\Documents\librerías\local\ antes de descargar. Volver al índice de los 66 estudios.