由于老版本文档中提供的例子、已经跟不上开发组版本的更新速度。在此一起探讨下,新版本中截图和分享如何实现,如何破坑!抛砖引玉!
需求:1、截图展示。2、保存本地PNG
下面把测试使用的代码奉上,还请各位大咖,大神,大侠,大哥,大姐帮帮忙
@property(Node)
targetSprite?:Node;
camera?:Camera;
start () {
// [3]
this.web_share()
this.web_createImg()
}
public texture?:RenderTexture;
web_share() {
this.camera = find("Canvas").getChildByName("Camera").getComponent(Camera)
this.texture = new RenderTexture();
this.texture.reset(view.getVisibleSize());
this.camera.targetTexture = this.texture;
let newSpFrame = new SpriteFrame();
newSpFrame.texture = this.texture;
this.targetSprite.getComponent(UITransform).contentSize = view.getVisibleSize();
this.targetSprite.getComponent(Sprite).spriteFrame = newSpFrame;
this.scheduleOnce(()=>{
this.camera.targetTexture = null;
}, 0);
// 截出来的图倒立,逆天了
this.targetSprite.setScale(new Vec3(1, -1, 1))
}
/**
* 保存到本地不知何去何从,尝试了大咖们各种解题思路,短时间竟然依旧毫无进展
*/
web_createImg () {
}