Phaser3 pixel rendering

CNPM 2021-02-23 16:11:00
phaser3 phaser pixel rendering

How elegant in today's uneven hardware performance C End rendering canvas canvas

The background that

At present, I mainly struggle in C The front line of education products , In the early stage of development, only the user's image quality experience was considered, but not in high resolution And related The display card has low memory It's impossible to Full frame rate rendering Use , a High load state .

Discover problems in time

canvas Canvas pixel density rendering too high

The current solution is :iPad and PC Uniform according to the screen resolution length and width x2 times (window.devicePixelRatio) Again x1.5 Multiple rendering , In fact, it is based on 6 Multiple power rendering , Android is the default pixel 1.2 times .

For the above problems , High pixel density rendering will provide good image quality , But for the core or low memory users, it will cause too high GPU Consume , Specific performance: :

  • User behavior response time Too long
  • The fan speeds up , equipment fever serious
  • Elements in browser windows cannot be 60FPS Dynamic rendering , All animations in Windows Drop frame obvious


After finding the problem, two strategies are provided :

  • Give priority to user performance experience , Give up part of the picture quality experience ;
  • Give priority to user experience , Give up the performance experience .

When the user's hardware device limit cannot be controlled , Without affecting the good experience of most users ,‘ programme 1’ Is the best quick solution .

Practical solution

  • Provides a maximum rendering total pixel
  • Get the current window resolution, multiply and compare with the maximum pixel CURRENT > MAX ? Rendering MAX : Rendering CURRENT
  • At the same time, consider the low performance and anti aliasing of some Android devices , Render 0.9 Times the total pixels ;iOS and PC GPU The performance is generally strong , Render 1.2 Multiple pixels

Post optimization space

At present, the first iteration takes the default “ programme 1”, Consider joining “ Dynamic selection ” function , Let users choose according to their own experience , programme 1 perhaps 2.

The specific judgment conditions are to be determined , draft :

  • PCAPP、iPad、 Android pad Tell... By bridge agreement GPU Rendering situation , There is an abnormally high value GPU Pop up window to choose whether to reduce the image quality ;
  • Based on the scheme that now provides maximum rendering total pixels , Every initialization canvas In front of canvas , Judge physical pixel and threshold pixel , Provide users with “ High quality ” perhaps “ High performance ” Options .

Phaser3 Rendering miscellany

Effect comparison

Performance before optimization

 Before optimization FPS

Performance after optimization

 After optimization FPS


  1. RxHttp - 轻量级、可扩展、易使用、完美兼容MVVM、MVC架构的网络封装类库
  2. Rxhttp - lightweight, extensible, easy to use, perfectly compatible with MVVM, MVC architecture network encapsulation class library
  3. Rxhttp - lightweight, extensible, easy to use, perfectly compatible with MVVM, MVC architecture network encapsulation class library
  4. 前端面试常考题:JS垃圾回收机制
  5. Frequently asked questions in front end interview: JS garbage collection mechanism
  6. Rxhttp - lightweight, extensible, easy to use, perfectly compatible with MVVM, MVC architecture network encapsulation class library
  7. Java之HTTP网络编程(一):TCP/SSL网页下载
  8. HTTP network programming in Java (1): TCP / SSL web page download
  9. Java之HTTP网络编程(一):TCP/SSL网页下载
  10. HTTP network programming in Java (1): TCP / SSL web page download
  11. 使用vite搭建vue项目
  12. 在组件中展示pdf文件:vue-pdf (由于未找到方法滑动加载下一页,只能点击加载下一页pdf文件)
  13. 在 vue 中通过 express 连接数据库
  14. Using vite to build Vue project
  15. Display PDF file in component: Vue pdf
  16. Connecting database through express in Vue
  17. 2021届秋招哈啰出行前端面经(一面)
  18. vue使用sdk进行七牛云上传
  19. Javascript性能优化【内联缓存】 V8引擎特性
  20. Small true wireless smart headset evaluation: put intelligence into the ear
  21. The front end experience of the 2021 autumn recruitment
  22. Vue uses SDK to upload Qi Niu cloud
  23. 深入理解 Web 协议 (三):HTTP 2
  24. dhtmlxGantt如何重新排序任务
  25. JavaScript performance optimization [inline cache] V8 engine features
  26. 深入理解 Web 协议 (三):HTTP 2
  27. Deep understanding of Web protocol (3): http 2
  28. 深入理解 Web 协议 (三):HTTP 2
  29. How dhtmlxgantt reorders tasks
  30. 深入理解 Web 协议 (三):HTTP 2
  31. JavaScriptBOM操作
  32. JavaScriptBOM操作
  33. Deep understanding of Web protocol (3): http 2
  34. Deep understanding of Web protocol (3): http 2
  35. dhtmlxGantt甘特图重新排序任视频教程
  36. vue实现七牛云上传图片功能
  37. vue.js环境配置步骤及npm run dev报错解决方案
  38. Deep understanding of Web protocol (3): http 2
  39. JavaScript BOM operation
  40. JavaScript BOM operation
  41. Dhtmlxgantt reordering video tutorial
  42. Vue to achieve seven cattle cloud upload image function
  43. vue.js Environment configuration steps and NPM run dev error reporting solution
  44. 什么是HTTPS以及如何实施HTTPS?
  45. vue使用sdk进行七牛上传
  46. JavaScript 邮箱验证 - 正则验证
  47. Codeless development platform cloud watch sets off a "new revolution" in enterprise Digitalization
  48. Codeless development of cloud watch for enterprise digital solution
  49. What is HTTPS and how to implement it?
  50. Vue uses SDK to upload seven cows
  51. JavaScript mailbox verification - regular verification
  52. JavaScriptBOM操作
  53. JavaScript BOM operation
  54. How to create a new NPM package and publish it to the NPM community
  55. vue --tinymce 解决上传图片的方法
  56. Vue development
  57. A simple solution for vite to batch introduce SVG symbol
  58. Building 3D rendering engine from scratch with JS (2)
  59. Vue -- tinymece solution to upload pictures
  60. Common configuration of nginx