2.0 截图出来的纹理是倒立的,在使用之前我想把图片翻转过来,查api得到setFlipY方法,代码如下
const {ccclass, property} = cc._decorator;
@ccclass
export class HelloWorld extends cc.Component {
@property(cc.Node)
target: cc.Node = null;
@property(cc.Sprite)
resultSprite: cc.Sprite = null;
@property(cc.Camera)
captureCamera: cc.Camera = null;
start() {
let rt = this.capture(this.target);
rt.setFlipY(true);
let spriteFrame = new cc.SpriteFrame(rt);
//rt.setFlipY(true);
this.resultSprite.spriteFrame = spriteFrame;
//spriteFrame.getTexture().setFlipY(true);
}
capture(captureNode: cc.Node) {
let rt = new cc.RenderTexture();
//rt.setFlipY(true);
rt.initWithSize(captureNode.width, captureNode.height);
this.captureCamera.targetTexture = rt;
this.captureCamera.render(captureNode);
//rt.setFlipY(true);
return rt;
}
}
我尝试了各个阶段调用这个方法,都无效
附demoflip-test.zip (570.8 KB)
ps:翻转node确实可以达到效果,但是破坏了截图功能的独立性