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

AnimationFrame: 增加帧率的耗时

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