인프런 커뮤니티 질문&답변
수리검이 날아가지 않습니다
작성
·
185
0
const renderGame에서 keyMotion()까지는 작동을 하는데그 이후 forEach부분부터는 작동하지 않는것같습니다, 왜이럴까요?오타도 없고 아무이상없습니다!혹시 window.requestAnimationFrame이 너무 빨라서 bulletComProp foreach가 씹히는걸까요? ㅠㅠ... 코드 보내드립니다
<game.js>
const renderGame = () => {
   hero.keyMotion();
   bulletComProp.arr.forEach((arr,i)=>{
      arr.moveBullet();
   })
   window.requestAnimationFrame(renderGame);
}
<class.js>
 if(key.keyDown['attack']){
         this.el.classList.add('attack');
         bulletComProp.arr.push(new Bullet());
      }
class Bullet {
   constructor(){
      this.parentNode = document.querySelector(".game");
      this.el = document.createElement("div");
      this.el.className = "hero_bullet";
      this.x = 0;
      this.y = 0;
      this.speed = 30;
      this.distance = 0;
      this.init();
   }
   init(){
      this.x = hero.position().left + hero.size().width/2;
      this.y = hero.position().bottom - hero.size().height/2;
      this.el.style.transform = `translate(${this.x}px, ${this.y}px)`;
      this.parentNode.appendChild(this.el);
   }
   moveBullet(){
      this.distance += this.speed;
      this.el.style.transform = `translate(${this.distance}px, 100)`;
      this.el.style.backgroundColor = 'red';
   }
}




안녕하세요 ~ 🙂 스스로 해결하셨다니 다행입니다.
그럼 다른 궁금증이 생기면 문의주세요 :)