안에 내 질문은 다음과 관련이있다 : 나는 간단한 애니메이션 루프를 구현하기 위해 노력하고있어자바 스크립트는 - '이것은'에서는 setTimeout 및 requestAnimationFrame
setTimeout() inside JavaScript Class using “this”
calling a function inside setTimeout and inside a function
. draw 함수는 상태 객체의 멤버 함수입니다. setTimeout 및 requestAnimationFrame 내에서 'this'가 작동하는 데 문제가 있습니다. 내가) (플레이를 호출 할 때
ANIM.State.prototype = {
constructor: ANIM.State,
play: function(){
if(!this.paused){
var that = this;
setTimeout(function(){
requestAnimationFrame(that.play);
that.setFrameNum(that.currentFrame + 1); //draw code is in here
}, 1000/24);
}
}
};
는 그러나, 두 번 실행 중지 :
나는 다음과 같은 코드가 있습니다.
더 좋은 방법이 있나요? 가능하다면이 함수를 클래스 함수로 유지하고 전역 함수로 유지하고 싶습니다.