2.0.1 RenderTexture.setFlipY翻转纹理方法无效,附demo

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确实可以达到效果,但是破坏了截图功能的独立性

1赞

翻转node也是倒的

官方文档

文档中的这一块代码就是在做反转的事情

一些可以参考的帖子看下面的,论坛中还有不少这方面的讨论,可以搜索一下看看
https://forum.cocos.com/t/2-1-3-4/72655
https://forum.cocos.com/t/cocoscreator/72580?u=bigbear

你没有理解这个问题的精髓,我想问的是这个setFlipY函数不好使。另外你说的这个只能在web端,原生哪有document。

很久很久以前,已经确认setFlipY无效这个bug了,然后就没有然后了

原生的请参考官方范例合集中的capture_to_native

例子里面原生、web、微信三个平台的例子都有,可以参考

setFilpY针对Texture2D还是有效的,至于RenderTexture需要查一下

我已经解决这个问题,参考我发的最新文档。

哎,我看着这些方法都是通过readPixels重写一遍,实在是太麻烦了。RenderTexture的setFlipY不好使,那就曲线救国一下呗。
let newSf = new cc.SpriteFrame(texture);
newSf.setFlipY(true);
这样就解决了。

1赞

都2021了,还没修复!