Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
Hay 3 métodos "this.add.rectangle()", "new Phaser.GameObjects.Rectangle()" y "fillRectShape()", ¿cuándo debo usar cuál?

Soy nuevo en Phaser 3 y trato de descubrir la diferencia entre los (al menos) 3 métodos para crear rectángulos. Aquí está el código

 var game = new Phaser.Game({ scene: { create: create } }); function create() { let rect1 = this.add.rectangle(300, 100, 100, 30, 0x00f000, .5); let rect2 = new Phaser.GameObjects.Rectangle(this, 300, 150, 100, 30, 0xf00000) this.add.existing(rect2); let rect3 = this.add.graphics({ fillStyle: { color: 0x00f0f0 } }); let rect = new Phaser.Geom.Rectangle(300, 200, 100, 30); rect3.fillRectShape(rect); }
 <script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>

rect1 usa el más simple que solo necesita 1 línea de código.

rect2 instancia la clase Phaser.GameObjects.Rectangle . Supongo que es más poderoso si necesito un montón de objetos rectangulares donde puedo crear una subclase de la clase, predefinir algunas propiedades y métodos e instanciar mi objeto rectangular personalizado.

rect3 usa Phaser.GameObjects.Graphics que no puedo imaginar su caso de uso donde supera a los dos anteriores. ¿Alguien podría darme una pista?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La respuesta corta:

  • si necesita un rectángulo para límites u otros cálculos, use: new Phaser.Geom.Rectangle(...)
  • si necesita un GameObject de rectángulo simple, use: this.add.rectangle(...)
    • si no desea agregarlo a la escena de inmediato, use: new Phaser.GameObjects.Rectangle(...)
  • si necesita un GameObject rectangular especial con más campanas y silbatos, use: this.add.graphics(...)

La respuesta larga:

Depende de la tarea en cuestión. Dado que cada Objeto crea más o menos un Objeto diferente con diferentes propiedades/métodos.

  • Escriba Phaser.GameObjects.Graphics :
    Es un GameObject pero de muy "bajo nivel", puedes pintar casi cualquier cosa en él. como rectángulos, círculos, ... pero es más trabajo.
    Los detalles se pueden encontrar aquí https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Graphics.html

Aquí un ejemplo de un rectángulo especial : https://phaser.io/examples/v3/view/game-objects/graphics/fill-rounded-rectangle

  • Escriba Phaser.GameObjects.Rectangle :
    Es un GameObject como el Phaser.GameObjects.Graphics , pero está especializado para crear rectángulos.
    this.add.rectangle(...) y new Phaser.GameObjects.Rectangle(...) crean un rectángulo de este tipo. this.add.rectangle es solo una forma más conveniente de lograr esto y lo agrega directamente a la escena actual.
    Los detalles se pueden encontrar aquí https://photonstorm.github.io/phaser3-docs/Phaser.GameObjects.Rectangle.html )

Aquí un ejemplo de rectángulos básicos : https://phaser.io/examples/v3/view/game-objects/shapes/rectangle

  • Escriba Phaser.Geom.Rectangle :
    Es una forma geométrica, buena para límites y/u otros cálculos (pero también puedes dibujar con ella) .
    Los detalles se pueden encontrar aquí https://photonstorm.github.io/phaser3-docs/Phaser.Geom.Rectangle.html

Aquí un ejemplo de cómo se usa para verificar si un GameObject está en un rectángulo específico:https://phaser.io/examples/v3/view/geom/rectangle/contains-rect

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!