提交 8adff6d4 编写于 作者: H hdx

AnimationFrame: 增加帧率的耗时

上级 9996374d
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<button @click="startRequestAnimationFrame">requestAnimationFrame</button> <button @click="startRequestAnimationFrame">requestAnimationFrame</button>
<button @click="stopRequestAnimationFrame">cancelAnimationFrame</button> <button @click="stopRequestAnimationFrame">cancelAnimationFrame</button>
<text class="frame-count">FPS: {{fps}}</text> <text class="frame-count">FPS: {{fps}} / {{formatFPSTime}}</text>
<text class="frame-count">FrameCount: {{testFrameCount}}</text> <text class="frame-count">FrameCount: {{testFrameCount}}</text>
<text class="tips">提示: 在当前测试例子中,每增加一次调用 requestAnimationFrame 帧率翻倍,cancelAnimationFrame 后恢复</text> <text class="tips">提示: 在当前测试例子中,每增加一次调用 requestAnimationFrame 帧率翻倍,cancelAnimationFrame 后恢复</text>
</view> </view>
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
title: 'AnimationFrame', title: 'AnimationFrame',
taskId: 0, taskId: 0,
fps: 0, fps: 0,
formatFPSTime: '0ms',
lastTime: 0, lastTime: 0,
frameCount: 0, frameCount: 0,
testFrameCount: 0 testFrameCount: 0
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
this.taskId = requestAnimationFrame((timestamp : number) => { this.taskId = requestAnimationFrame((timestamp : number) => {
this.frameCount++ this.frameCount++
if (timestamp - this.lastTime >= 1000) { if (timestamp - this.lastTime >= 1000) {
this.formatFPSTime = (1000 / this.frameCount).toFixed(3) + 'ms'
this.fps = this.frameCount this.fps = this.frameCount
this.frameCount = 0 this.frameCount = 0
this.lastTime = timestamp this.lastTime = timestamp
...@@ -42,6 +44,7 @@ ...@@ -42,6 +44,7 @@
}, },
stopRequestAnimationFrame() { stopRequestAnimationFrame() {
this.fps = 0 this.fps = 0
this.formatFPSTime = '0ms'
this.lastTime = 0 this.lastTime = 0
this.frameCount = 0 this.frameCount = 0
cancelAnimationFrame(this.taskId) cancelAnimationFrame(this.taskId)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册