博客
关于我
creator摄像机的使用
阅读量:511 次
发布时间:2019-03-07

本文共 1728 字,大约阅读时间需要 5 分钟。

onToast() {    // 即使除了最底层摄像机外,其它摄像机不需要全都打勾,这样会防止上层摄像机将下层摄像机的画面清除    // 1. 深度    // 深度用于决定摄像机渲染的顺序,值越大渲染越晚    // 最后一个渲染的摄像机才会显示最终的场景    // 2. 分组    // 主摄像机不包含被截图的分组,摄像机会更高效地获取被截图的节点    // 被截图的节点默认应修改为特定分组    // 3. 摄像机跟随    // 摄像机应跟随采图节点,否则可能无法正确获取所需图像    // 即使不跟随,也可以利用深度配置,让底层摄像机捕捉所需区域上层摄像机清除画面    const cameras = cc.Camera.cameras;    cc.log("cc.Camera.cameras =", cameras);    // 示例说明    // node = new cc.Node();    // node.parent = cc.director.getScene();    // camera = node.addComponent(cc.Camera);    const smile = cc.find("smile", this.node);    let camera = cc.Camera.findCamera(smile);    cc.log("Found camera =", camera);    // 仅供参考,具体实现可根据需求调整    camera.x = smile.x;    camera.y = smile.y;    // 示例配置    const texture = new cc.RenderTexture();    const gl = cc.game._renderContext;    const width = smile.width * 5;    const height = smile.height * 5;    texture.initWithSize(cc.visibleRect.width, cc.visibleRect.height, gl.STENCIL_INDEX8);    camera.targetTexture = texture;    camera.render();    const data = texture.readPixels();    const canvas = document.createElement('canvas');    const ctx = canvas.getContext('2d');    canvas.width = texture.width;    canvas.height = texture.height;    const rowBytes = canvas.width * 4;    for (let row = 0; row < height; row++) {        const srow = height - 1 - row;        const imageData = ctx.createImageData(canvas.width, 1);        const start = srow * rowBytes;        for (let i = 0; i < rowBytes; i++) {            imageData.data[i] = data[start + i];        }        ctx.putImageData(imageData, 0, row);    }    const dataUrl = canvas.toDataURL('image/jpeg');    const img = document.createElement('img');    img.src = dataUrl;    cc.log("dataUrl =", dataUrl);}

转载地址:http://easjz.baihongyu.com/

你可能感兴趣的文章
poj 1286 Necklace of Beads
查看>>
POJ 1321 棋盘问题
查看>>
poj 1321(回溯)
查看>>
Qt高级——Qt元对象系统源码解析
查看>>
qt调用vs2008编写的dll动态库(隐式调用)
查看>>
Qt读取注册表默认值
查看>>
poj 1679 判断MST是不是唯一的 (次小生成树)
查看>>
POJ 1703 Find them, Catch them
查看>>
POJ 1703 Find them, Catch them 并查集
查看>>
POJ 1738 An old Stone Game(石子合并)
查看>>
POJ 1740 A New Stone Game(博弈)题解
查看>>
Qt网络编程之实例二POST方式
查看>>
POJ 1765 November Rain
查看>>
poj 1860 Currency Exchange
查看>>
POJ 1961 Period
查看>>
POJ 2019 Cornfields (二维RMQ)
查看>>
poj 2057 The Lost House 贪心思想在动态规划上的应用
查看>>
poj 2057 树形DP,数学期望
查看>>
poj 2112 最优挤奶方案
查看>>
Qt编写自定义控件12-进度仪表盘
查看>>