微信小游戏中three.js实现离屏画布-创新互联
这期内容当中小编将会给大家带来有关微信小游戏中three.js实现离屏画布,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

在微信小游戏中,把three.js的3D内容在离屏画布处理,然后复制到在屏画布,方法是:
let c_toolbarHeight=140;
let sysInfo=wx.getSystemInfoSync();
require('./js/libs/weapp-adapter.js');
var canvas_webGL=window.canvas;
canvas_webGL.width = sysInfo.screenWidth * sysInfo.pixelRatio;
canvas_webGL.height = (sysInfo.screenHeight-c_toolbarHeight) * sysInfo.pixelRatio;
var ctx_webGL=canvas_webGL.getContext('webgl');
let options={context: ctx_webGL}
let renderer = new THREE.WebGLRenderer(options);
renderer.setSize(sysInfo.screenWidth, sysInfo.screenHeight-c_toolbarHeight);
renderer.setPixelRatio(sysInfo.pixelRatio);
function render(){
//清除canvas_bkg的3D区域
wx.tmGlobal.eraseZone(0,
c_toolbarHeight,
sysInfo.screenWidth,
sysInfo.screenHeight);
renderer.render(scene, camera);
wx.tmGlobal.ctx_bkg.drawImage(canvas_webGL,
0,c_toolbarHeight*sysInfo.pixelRatio);
//画一条横的红线
wx.tmGlobal.ctx_bkg.strokeStyle = '#FF8C00';
wx.tmGlobal.ctx_bkg.lineWidth = 2;
wx.tmGlobal.ctx_bkg.beginPath();
wx.tmGlobal.ctx_bkg.moveTo(0,
(c_toolbarHeight)*sysInfo.pixelRatio);
wx.tmGlobal.ctx_bkg.lineTo(
sysInfo.screenWidth*sysInfo.pixelRatio,
(c_toolbarHeight)*sysInfo.pixelRatio);
//画游戏结束临界线
wx.tmGlobal.ctx_bkg.moveTo(0,
(c_toolbarHeight+c_yugaoHeight)*sysInfo.pixelRatio);
wx.tmGlobal.ctx_bkg.lineTo(
sysInfo.screenWidth*sysInfo.pixelRatio,
(c_toolbarHeight+c_yugaoHeight)*sysInfo.pixelRatio);
wx.tmGlobal.ctx_bkg.stroke();
//把canvas_bkg画到在屏画布
wx.tmGlobal.ctx_main.clearRect(0,0,
wx.tmGlobal.canvas_main.width,wx.tmGlobal.canvas_main.height);
wx.tmGlobal.ctx_main.drawImage(wx.tmGlobal.canvas_bkg,0,0);
} 当前名称:微信小游戏中three.js实现离屏画布-创新互联
标题链接:http://www.jxjierui.cn/article/ejcig.html


咨询
建站咨询
