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

你可能感兴趣的文章
PHP pcntl_fork不能在web服务器中使用的变通方法
查看>>
php private ,public protected三者的区别
查看>>
php PSR规范
查看>>
php rand() 重复,array_rand()函数从另外一个数组中随机取得的一定数量的数组的元素是否会重复?...
查看>>
php redis pub/sub(Publish/Subscribe,发布/订阅的信息系统)之基本使用
查看>>
php redis 集群扩展类文件
查看>>
php redis(2)
查看>>
PHP Redis分布式锁
查看>>
php session超时时间_php怎么设置session超时时间
查看>>
PHP SOAP模块的使用方法:NON-WSDL模式
查看>>
php Socket通信
查看>>
PHP SPL标准库-迭代器
查看>>
PHP Static延迟静态绑定
查看>>
php str_pad();
查看>>
PHP study 环境变量composer
查看>>
PHP trim() 函数
查看>>
php unicode编码转成unioce字符(中文)
查看>>
php url路径问题和php文件以绝对路径引入
查看>>
PHP WebSehll 后门脚本与检测工具
查看>>
ReentrantLock源码解析
查看>>