当前位置:网站首页>three. JS text ambiguity problem
three. JS text ambiguity problem
2022-04-23 13:01:00 【llsxily】
https://github.com/jsmask/JumpGame/
See this today jsmask Great God wrote a jump web page , be based on three.js Written .
Compile and run directly , Really excited , But there is also a problem .
Is in the source code GAME OVER The words and pictures on the scene are very blurred
I found a circle on the Internet , First, we found the method of overall optimization , However, the picture of text and pictures after overall optimization is not very ideal .
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
And then they found out CANVAS Image optimization method , Can be used to optimize :
You can see https://www.geeksforgeeks.org/how-to-sharpen-blurry-text-in-html5-canvas/
On the left is the optimized , On the right is before optimization .
The basic principle is , adopt canvas.content Of scale Method to enlarge the canvas , Draw an enlarged picture on it , And then through thress Zoom , Improve the resolution of the picture . That is to draw a picture twice as big , Shrink and come back .
The optimized code is as follows :
this.context = canvas.getContext('2d');
// The core
this.context.scale(scale, scale)
this.context.fillStyle = 'rgba(0,0,0,.7)';
this.context.fillRect(((width - 400) / 2) /scale, ((height - 400 ) / 2)/scale, 400 /scale, 400/scale);
this.context.fillStyle = '#eee';
this.context.font = '11px Georgia';
this.context.fillText('Game Over', ((width - 200) / 2 - 15) /scale, ((height - 200) / 2 + 55)/scale);
this.replay_btn = new Image();
this.replay_btn.onload = () => {
this.context.drawImage(this.replay_btn, ((width / 2 - 60) /2) /scale , ((height - 200) / 2 + 125)/scale, 240 /scale, 94/ scale);
}
this.replay_btn.src = img_replay;
// The core
this.geometry = new THREE.PlaneGeometry(30, 30 * aspect);
The source code is as follows :
this.context = canvas.getContext('2d');
this.context.fillStyle = 'rgba(0,0,0,.7)';
this.context.fillRect((width - 200) / 2, (height - 200) / 2, 200, 200);
this.context.fillStyle = '#eee';
this.context.font = '22px Georgia';
this.context.fillText('Game Over', (width - 200) / 2 + 45, (height - 200) / 2 + 55);
this.replay_btn = new Image();
this.replay_btn.onload = () => {
this.context.drawImage(this.replay_btn, width / 2 - 60, (height - 200) / 2 + 125, 120, 47);
}
this.replay_btn.src = img_replay;
this.geometry = new THREE.PlaneGeometry(60, 60 * aspect);
After writing, I suddenly remembered that there was a time when the definition of the QR code picture generated by the front end was not enough. It was also through Mr. Cheng to enlarge the picture , Then reduce the display form to complete . This is the same principle as that .
版权声明
本文为[llsxily]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231259116618.html
边栏推荐
- Jiachen chapter Genesis "inner universe" joint Edition
- Servlet监听器&过滤器介绍
- jmeter操作redis
- unity常见的问题(一)
- 安装nngraph
- 4. DRF permission & access frequency & filtering & sorting
- Record Alibaba cloud server mining program processing
- 22. 括号生成
- Go language: passing slices between functions
- Remote sensing image classification and recognition system based on convolutional neural network
猜你喜欢
98. Error s.e.errormvcautoconfiguration $staticview reported by freemaker framework: cannot render error page for request
STM32 is connected to the motor drive, the DuPont line supplies power, and then the back burning problem
Synchronously update the newly added and edited data to the list
梳理網絡IP代理的幾大用途
Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)
SSM框架系列——注解开发day2-2
软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。
Unable to create servlet under SRC subfile of idea
内核错误: No rule to make target ‘debian/canonical-certs.pem‘, needed by ‘certs/x509_certificate_list‘
Summary of JVM knowledge points - continuously updated
随机推荐
在线计算过往日期天数,计算活了多少天
Packet capturing and sorting -- TCP protocol [8]
[csnote] ER diagram
梳理网络IP代理的几大用途
About the 'enum' enumeration type and structure.
Redis deployment of cloud native kubesphere
Customize the shortcut options in El date picker, and dynamically set the disabled date
Custom nail robot alarm
(1) Openjuterpyrab comparison scheme
Use source insight to view and edit source code
Free and open source agricultural Internet of things cloud platform (version: 3.0.1)
How to prevent the website from being hacked and tampered with
World Book Day: I'd like to recommend these books
将新增和编辑的数据同步更新到列表
Subscribe to Alibaba demo send business messages
Community version Alibaba MQ ordinary message sending subscription demo
【蓝桥杯】4月17日省赛刷题训练(前3道题)
Golang realizes regular matching: the password contains at least one digit, letter and special character, and the length is 8-16
mysql8安装
Start mqbroker CMD failure resolution