Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
Box creation is making the physics pause

This is the code to create a box, this code is called when you click the down key. I would like help making a box that spawns at the bottom of my screen and moves across the page

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);
}

I also create the box once in the create function and it works

I get the error: TypeError: Cannot read properties of undefined (reading 'add')

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

the problem is that in your down event function, you didn't passt the scene as context. I'm to sure which method you are using, but here an example what I mean:

  • If you are using the input.keyboard.on way (here the documentation):

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

the final this is the scene, that you need to pass to the keyboard event-callback. So that the this in your function createBox points to the sceneand not to the browser window;

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda