inflearn logo
강의

講義

知識共有

Webゲームを作って学ぶインタラクティブWeb! JAVASCRIPT

手裏剣を動かす

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

237

litzoo

投稿した質問数 4

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/CSS javascript 인터랙티브-웹

回答 1

0

litzoo

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

0

ggangcoding162118

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

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

용어 발음법이 계속 바뀌는 것 같은데 이런 부분들 개선이 가능할까요...?

0

7

1

counter01.html은 어디있을까요?

1

9

1

프로젝트 완성본 보내주실수 있나요?

0

61

1

캐릭터 기본 모션 만들기에서 포토샵에 열라고하는데 포토샵없으면 어떻게하죠? 공짜버전있나요?

0

206

1

renderGame 함수에 로그를 찍으면 무한루프가 돕니다

0

295

1

수리검 방지턱(?) 현상

0

495

2

requestanimationframe 성능관련 궁금증

0

601

1

frame 질문합니다.

0

351

2

개발툴은 어떤걸 사용하나요?

0

300

1

e.which에 대한 질문입니다.

1

611

1

수리검이 사라집니다

0

274

1

const 변수 및 Arrowfunction 방식 질문

0

430

2

몬스터나 npc의 위치가 일정 크기를 넘어가면 히어로가 사라집니다.

0

196

1

수리검 방향 전환 처리에서 간단한 질문 있습니다.

0

227

1

마이너스 좌표값(?) 사용

0

751

1

코딩작업하고 웹화면 띄워서 확인하는 방법?

0

534

2

캐릭터가 점프하면서 앞으로 나아가게 만들고있습니다

0

390

1

전체 이미지에서 원하는 부분만 컷하고 싶어요(사진첨부)

0

493

1

질문있습니다.

0

203

1

깃헙 레포 질문드립니다.

0

260

1

캐릭터 기본 모션 만들기, 경로가 인식이 안되요.

0

299

1

몬스터가 참조가 안되는 이슈가 있습니다.

0

359

1

기초적인 질문이라 부끄럽지만 질문 드립니다

0

413

1

공격키를 연속으로 누를때 처리하는 방법 질문 드립니다

0

941

2