작성
·
116
0
<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';
}
}
안녕하세요 ~ 🙂 스스로 해결하셨다니 다행입니다.
그럼 다른 궁금증이 생기면 문의주세요 :)