提交 2c174fea 编写于 作者: M Mr.doob

Using Extend pattern in Clock. Added more robust check for performance.now(). See #2975.

上级 3c06f0c5
......@@ -14,33 +14,33 @@ THREE.Clock = function ( autoStart ) {
};
THREE.Clock.prototype.start = function () {
THREE.extend( THREE.Clock.prototype, {
this.startTime = performance.now !== undefined ? performance.now() : Date.now();
this.oldTime = this.startTime;
start: function () {
this.running = true;
this.startTime = window.performance !== undefined && window.performance.now !== undefined
? window.performance.now()
: Date.now();
};
this.oldTime = this.startTime;
this.running = true;
},
THREE.Clock.prototype.stop = function () {
stop: function () {
this.getElapsedTime();
this.running = false;
};
},
THREE.Clock.prototype.getElapsedTime = function () {
getElapsedTime: function () {
this.getDelta();
return this.elapsedTime;
};
},
THREE.Clock.prototype.getDelta = function () {
getDelta: function () {
var diff = 0;
......@@ -52,7 +52,10 @@ THREE.Clock.prototype.getDelta = function () {
if ( this.running ) {
var newTime = performance.now !== undefined ? performance.now() : Date.now();
var newTime = window.performance !== undefined && window.performance.now !== undefined
? window.performance.now()
: Date.now();
diff = 0.001 * ( newTime - this.oldTime );
this.oldTime = newTime;
......@@ -62,4 +65,6 @@ THREE.Clock.prototype.getDelta = function () {
return diff;
};
}
} );
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册