亚洲欧美精品中文三区|亚洲精品美女AV在线|性生潮久久久不久久久久|免费 无码 国产在现看|亚洲欧美国产精品专区久久|少妇的丰满3中文字幕免费|欧美成人怡红院在线观看视频|亚洲国产中文精品看片在线观看

世界今熱點(diǎn):截圖!長(zhǎng)按保存分享!Cocos Creator

一種3D截圖方案

背景

參考 TRUE SPACE with Cocos 技術(shù)分享[1]中的動(dòng)態(tài)生成海報(bào)的介紹,以及作者的支持。實(shí)現(xiàn)一個(gè)長(zhǎng)按保存分享截圖的方案。

效果

在微信瀏覽器中預(yù)覽效果如下


(相關(guān)資料圖)

環(huán)境Cocos Creator 3.7.1Web 瀏覽器原理

原作者講的非常清楚,只需要按照以下步驟實(shí)現(xiàn)即可。

3D相機(jī)生成一個(gè)RT 賦予給2D精靈擺上一些二維碼等UIUI相機(jī)再生成一張RT讀取RT中的數(shù)據(jù),傳給 canvascanvas 生成圖片數(shù)據(jù)傳給 Image適配Image對(duì)象大小位置視頻

錄了一段操作視頻[2]供大家參考。

代碼

這段代碼的截圖功能是按照高度適配的方式寫的,如有其他需求,可自行修改相關(guān)邏輯。僅供大家參考學(xué)習(xí)。

import{_decorator,Component,Node,Camera,RenderTexture,view,UITransform,log,game,screen,NodeEventType}from"cc";const{ccclass,property}=_decorator;@ccclass("CaptureImage")exportclassCaptureImageextendsComponent{@property(Camera)copyCamera:Camera=null!;@property(Node)targetNode:Node=null!;@property(Node)captureBtn:Node=null!;@property(Node)closeBtn:Node=null!;rt:RenderTextureprivate_image:HTMLImageElement_canvas:HTMLCanvasElement=null!;_buffer:ArrayBufferView=null!;start(){log("歡迎關(guān)注微信公眾號(hào)【白玉無冰】https://mp.weixin.qq.com/s/4WwCjWBtZNnONh8hZ7JVDA")this.rt=newRenderTexture();this.rt.reset({width:view.getVisibleSize().width,height:view.getVisibleSize().height,})this.copyCamera.targetTexture=this.rt;this.captureBtn.active=true;this.closeBtn.active=false;this.captureBtn.on(NodeEventType.TOUCH_END,this.copyRenderTex,this)this.closeBtn.on(NodeEventType.TOUCH_END,this.clearCapture,this)}privatecopyRenderTex(){constwidth=this.targetNode.getComponent(UITransform).width;constheight=this.targetNode.getComponent(UITransform).height;constanchorPoint=this.targetNode.getComponent(UITransform).anchorPoint;constworldPos=this.targetNode.getWorldPosition();this._buffer=this.rt.readPixels(Math.round(worldPos.x-width*anchorPoint.x),Math.round(worldPos.y-height*anchorPoint.y),width,height);if(!this._canvas){this._canvas=document.createElement("canvas");this._canvas.width=width;this._canvas.height=height;}else{letctx=this._canvas.getContext("2d");ctx.clearRect(0,0,this._canvas.width,this._canvas.height);}letctx=this._canvas.getContext("2d")!;letrowBytes=width*4;for(letrow=0;row

其他

最近寫文偏筆記的形式,主要是記錄一下代碼,下次要用的時(shí)候再翻出來。希望對(duì)大家有所幫助。

參考資料

[1]

TRUE SPACE with Cocos 技術(shù)分享:https://forum.cocos.org/t/topic/146459

[2]

視頻:https://www.bilibili.com/video/BV1w84y1N7XQ

往期精彩:

3DUI Cocos Creator

三渲二 Cocos Creator

零代碼實(shí)現(xiàn)面片效果(UV滾動(dòng),幀動(dòng)畫) Cocos Creator

游戲開發(fā)資料合集,2022年版

點(diǎn)擊“閱讀原文”查看精選導(dǎo)航

“點(diǎn)贊“ ”在看”鼓勵(lì)一下▼

關(guān)鍵詞:

丰县| 奉节县| 资中县| 屏东县| 阿拉尔市| 天峻县| 砚山县| 琼海市| 威海市| 唐山市| 武冈市| 县级市| 黑山县| 上思县| 蒙自县| 苏尼特左旗| 正蓝旗| 茶陵县| 称多县| 共和县| 米泉市| 嘉义市| 海晏县| 巴楚县| 天柱县| 渭南市| 蓬溪县| 古丈县| 阿拉善右旗| 鄂托克前旗| 千阳县| 拉孜县| 平顶山市| 丰县| 宜都市| 民丰县| 乳山市| 珠海市| 姚安县| 叶城县| 特克斯县|