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

129
Views
La creación de cajas hace que la física se detenga

Este es el código para crear un cuadro, este código se llama cuando hace clic en la tecla hacia abajo. Me gustaría ayuda para hacer un cuadro que se genera en la parte inferior de mi pantalla y se mueve por la página

 var boxes function preload() { this.load.image('box', 'assets/box.png'); } function create() { this.w = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.W) this.a = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.A) this.s = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.S) this.d = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.D) box = this.physics.add.group(); boxes = box.create(0, 900, 'box').setScale(0.1); boxes.body.setAllowGravity(false); boxes.setVelocityX(200) this.physics.add.collider(player, boxes); } function update() { let cursors = this.input.keyboard.createCursorKeys(); if (this.s.isDown) { if (wait = 1) { createBox() } } } function createBox() { box = this.physics.add.group(); boxes = box.create(0, 900, 'box').setScale(0.1); boxes.body.setAllowGravity(false); boxes.setVelocityX(200) this.physics.add.collider(player, boxes); this.time.delayedCall(1000, delayer, null, this); }

También creo el cuadro una vez en la función de creación y funciona.

Recibo el error: TypeError: No se pueden leer las propiedades de undefined (leyendo 'agregar')

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

0

el problema es que en su función de evento inactivo , no pasó la escena como contexto. Estoy seguro de qué método está utilizando, pero aquí hay un ejemplo de lo que quiero decir:

  • Si está utilizando la forma input.keyboard.on ( aquí la documentación ):

     this.input.keyboard.on('keydown-DOWN', function (event) { // ... }, this); // <- finall *this* is very important

al final, this es la escena, que debe pasar al evento de devolución de llamada del teclado. Para que el this en su función createBox apunte a la scene y no a la window del navegador;

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!