강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của litzoo
litzoo

câu hỏi đã được viết

Tìm hiểu web tương tác bằng cách tạo trò chơi trên web! JAVASCRIPT

cho phi tiêu di chuyển

수리검이 날아가지 않습니다

Viết

·

205

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'; } }
HTML/CSSjavascript인터랙티브-웹

Câu trả lời 1

0

litzoo님의 프로필 이미지
litzoo
Người đặt câu hỏi

renderGame을 호출하지 않아서 생긴 문제엿네요 감사합니다!

ggangcoding162118님의 프로필 이미지
ggangcoding162118
Người chia sẻ kiến thức

안녕하세요 ~ 🙂 스스로 해결하셨다니 다행입니다.

그럼 다른 궁금증이 생기면 문의주세요 :)

Hình ảnh hồ sơ của litzoo
litzoo

câu hỏi đã được viết

Đặt câu hỏi