-
카테고리
-
세부 분야
게임 프로그래밍
-
해결 여부
미해결
수리검이 날아가지 않습니다
24.01.09 12:00 작성 조회수 59
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';
}
}
답변을 작성해보세요.
답변 1