2014-12-06 4 views
0

바르 T = 0requestAnimationFrame + 적용

...

VAR의 새로운 클래스의 TestClass =()

TestClass.extend({ 
     init: function() { 
      this.TT = T; 
      T++ 
     } 
    }); 

    TestClass.include({ 
     animate: function() { 
      A = this 
      window.requestAnimationFrame(function() { 
       A.animate(); 
       console.log(A.TT) 
      }); 
     } 
    }); 

...

var can1 = new TestClass(); 
    var can2 = new TestClass(); 
    var can3 = new TestClass(); 

...

var can1.animate() 
    var can2.animate() 
    var can3.animate() 

그래서 can3에서만 작동합니다. 콘솔 : >> 2

내가 할 것입니다 경우 :

TestClass.include({ 
     animate: function() 
     { 
      console.log(this.TT) 
     } 
    }); 

    var can1 = new TestClass(); 
    var can2 = new TestClass(); 
    var can3 = new TestClass(); 

    function G() { 
     window.requestAnimationFrame(function() { 
      can1.animate() 
      can2.animate() 
      can3.animate() 
      G() 
     }); 
    } 
    G() 

는 것이다 올바르게 작동합니다,하지만 난의 TestClass의 각 내부 requestAnimationFrame을 어떻게 할 수 있습니까?

답변

0

동일한 문제가 있습니다. 그렇게해라. 사용해보기 https://github.com/mixed/requestAnimationFrameInterval

TestClass.include({ 
    animate: function() { 
     A = this 
     window.requestAnimationFrameInterval(function() { 
      A.animate(); 
      console.log(A.TT); 
     }); 
    } 
}); 

var can1 = new TestClass(); 
var can2 = new TestClass(); 
var can3 = new TestClass(); 

var can1.animate() 
var can2.animate() 
var can3.animate() 

`

관련 문제