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

308
Visualizações
Cocos Creator: la colisión no funciona para los nodos agregados desde JS

Así que estoy tratando de agregar dinámicamente algunos obstáculos al juego, ahora este es el código completo relacionado con eso:

 cc.Class({ extends: cc.Component, properties: { ObstaclesGap: 180, Alive: true, XChange: 300, LastLowerX: 0, UpperObstacleSpritePrefab: cc.Prefab, LowerObstacleSpritePrefab: cc.Prefab, }, generateObstacle() { // Creation of obstacles const lowerObstacle = cc.instantiate(this.LowerObstacleSpritePrefab); const upperObstacle = cc.instantiate(this.UpperObstacleSpritePrefab); // Addition to canvas this.node.addChild(lowerObstacle); this.node.addChild(upperObstacle); // Setting sizes lowerObstacle.width = 60; upperObstacle.width = 60; /* Generates a number between 1 - 10, and multiply the lower obstacle's height with that number. The rest is then equals to the upper obstacle's height. All of that with a remaining 180 gap between them all of the time (which is 3 times the size of the bird) */ const rndNumber1t10 = Math.floor(Math.random() * 10)+1; lowerObstacleHeight = 540 * (rndNumber1t10 / 10); upperObstacleHeight = 540 * ((10 - rndNumber1t10) / 10); lowerObstacle.height = lowerObstacleHeight; upperObstacle.height = upperObstacleHeight; // Preperations for next obstacle positions lowerObstacle.getComponent(cc.PhysicsBoxCollider).size = cc.Size(60, lowerObstacleHeight) upperObstacle.getComponent(cc.PhysicsBoxCollider).size = cc.Size(60, upperObstacleHeight) this.LastLowerX += this.XChange; // Setting positions with a gap between the obstacles (720 - 180 = 540) lowerObstacle.setPosition(cc.v2(parseInt((-this.node.x) + this.LastLowerX), parseInt((-this.node.y) + 100 + lowerObstacleHeight / 2))); upperObstacle.setPosition(cc.v2(parseInt((-this.node.x) + this.LastLowerX), parseInt((-this.node.y) + 720))); }, onLoad() { for (let i = 0; i < 1; i++) { this.generateObstacle(); } }, start() { }, // update (dt) {}, });

Este es mi Gerente de Grupo:

ingrese la descripción de la imagen aquí

Y aquí hay un ejemplo para el de los Prefebs:

ingrese la descripción de la imagen aquí

El problema es que la colisión no ocurre entre el pájaro y los obstáculos, pero si arrastro manualmente al juego, chocará, por lo que debe haber algún problema con mi código.

about 4 years ago · Juan Pablo Isaza
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