cocos2dx-js RenderTexture 将多张图片合并成一张图片

var sprite = new cc.Sprite("about_btn.png");
        var sprite2 = new cc.Sprite("add5.png");

        //创建画布
        var rend = new cc.RenderTexture( starManager.winSize.width, starManager.winSize.height );

        sprite.setPosition(400,starManager.winSize.height/4);
        sprite2.setPosition(200,200);
        //设置精灵的坐标为cocos坐标
        sprite.setPosition(cc.director.convertToGL(sprite.getPosition()));
        sprite2.setPosition(cc.director.convertToGL(sprite2.getPosition()));
        //画
        rend.begin();
        sprite.visit();
        sprite2.visit();
        rend.end();

        var spt=new cc.Sprite();
        spt.setSpriteFrame(rend.getSprite().getSpriteFrame());//这里必须重新创建精灵,否则会报错
        spt.setAnchorPoint(cc.p(0,0));
        spt.setOpacity(100);
        this.addChild(spt);

你可能感兴趣的:(cocos-js)