当前位置:网站首页>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
边栏推荐
- JMeter operation redis
- PC starts multiple wechat at one time
- Byte jump 2020 autumn recruitment programming question: quickly find your own ranking according to the job number
- Go language mapping operation
- Common problems of unity (1)
- three.js文字模糊问题
- If you were a golang interviewer, what questions would you ask?
- Redis deployment of cloud native kubesphere
- Jupiter notebook installation
- Proteus 8.10 installation problem (personal test is stable and does not flash back!)
猜你喜欢
PC starts multiple wechat at one time
The quill editor image zooms, multiple rich text boxes are used on one page, and the quill editor upload image address is the server address
Bert base Chinese Download (SMART)
Object.keys后key值数组乱序的问题
SSM framework series - data source configuration day2-1
R语言中dcast 和 melt的使用 简单易懂
World Book Day: I'd like to recommend these books
mysql支持ip访问
Teach you to quickly develop a werewolf killing wechat applet (with source code)
有趣的IDEA插件推荐,给你的开发工作增添色彩
随机推荐
SSL certificate refund instructions
Servlet监听器&过滤器介绍
CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
Date time type in database
STD:: shared of smart pointer_ ptr、std::unique_ ptr
The El table horizontal scroll bar is fixed at the bottom of the visual window
22. Bracket generation
leetcode:437. Path sum III [DFS selected or not selected?]
MySQL supports IP access
Remote sensing image classification and recognition system based on convolutional neural network
云原生KubeSphere部署Redis
[csnote] ER diagram
4. DRF permission & access frequency & filtering & sorting
Pytorch: a pit about the implementation of gradreverselayer
STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
安装nngraph
31. Next arrangement
At instruction of nbiot
Keyword interpretation and some APIs in RT thread
21 days learning mongodb notes