当前位置:网站首页>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
边栏推荐
- Golang implements a five insurance and one gold calculator with web interface
- 22. Bracket generation
- [vulnhub range] - DC2
- Use compressorjs to compress pictures, optimize functions, and compress pictures in all formats
- Deploying MySQL in cloud native kubesphere
- 云原生KubeSphere部署Mysql
- Synchronously update the newly added and edited data to the list
- Record a website for querying compatibility, string Replaceall() compatibility error
- Important knowledge of network layer (interview, reexamination, term end)
- Ad20 supplementary note 3 - shortcut key + continuous update
猜你喜欢

CVPR 2022 & ntire 2022 | the first transformer for hyperspectral image reconstruction

XinChaCha Trust SSL Organization Validated

Custom nail robot alarm

Process virtual address space partition

数据库中的日期时间类型

软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。

Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)

云原生KubeSphere部署Redis

8 websites that should be known for product development to enhance work experience
![[vulnhub range] - DC2](/img/b7/c34f69a231dad653b8a912f1f36bef.png)
[vulnhub range] - DC2
随机推荐
Fashion cloud learning - input attribute summary
No idle servers? Import OVF image to quickly experience smartx super fusion community version
Date time type in database
Navicat远程连接数据库 出现 1130- Host xxx is not allowed to connect to this MySQL server错误
Servlet监听器&过滤器介绍
Wonderful review | the sixth issue of "source" - open source economy and industrial investment
进程虚拟地址空间区域划分
HQL statement tuning
Golang implements MD5, sha256 and bcrypt encryption
CVPR 2022 & ntire 2022 | the first transformer for hyperspectral image reconstruction
Custom nail robot alarm
Start mqbroker CMD failure resolution
产品开发都应该知道的8个网站,增强工作体验
98. Error s.e.errormvcautoconfiguration $staticview reported by freemaker framework: cannot render error page for request
Aviation core technology sharing | overview of safety characteristics of acm32 MCU
Teach you to quickly develop a werewolf killing wechat applet (with source code)
31. Next arrangement
Baserecyclerviewadapterhelper realizes pull-down refresh and pull-up loading
Jupiter notebook installation
There is no need to crack the markdown editing tool typora