博客
关于我
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/

你可能感兴趣的文章
pip install 出现报asciii码错误的解决
查看>>
pip throws TypeError: parse() got an unexpected keyword argument ‘transport_encoding‘ 在尝试安装新软件包时
查看>>
pip 下载慢
查看>>
pip 升级报错AttributeError: ‘NoneType’ object has no attribute ‘bytes’
查看>>
pip 安装出现异常
查看>>
Pip 安装失败:需要 SSL
查看>>
Pip 安装挂起
查看>>
pip/pip3更换国内源
查看>>
pip3 install PyQt5 --user 失败
查看>>
pip3命令全解析:Python3包管理工具的详细使用指南
查看>>
pip3安装命令重复创建文件‘/tmp/pip-install-xxxxx/package‘失败
查看>>
PIPE 接口信号列表
查看>>
pipeline项目配置实战
查看>>
Pipenv 与 Conda?
查看>>
QVGA/HVGA/WVGA/FWVGA分辨率屏含义及大小//Android虚拟机分辨率
查看>>
pipreqs : 无法将“pipreqs”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径 正确,然后再试一次。
查看>>
pipy国内镜像的网址
查看>>
quiver绘制python语言
查看>>
pip下载缓慢
查看>>
PIP使用SSH从BitBucket安装自定义软件包,无需输入SSH密码
查看>>