"use strict";
cc._RF.push(module, '24d006uysBPPL1WfuFgiflf', 'Home');
// Home.ts

Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var Home = /** @class */ (function (_super) {
    __extends(Home, _super);
    function Home() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.camera = null;
        _this.targetsp = null;
        _this.image = null;
        _this.renderTexture = null;
        _this.curr = 0;
        return _this;
    }
    // LIFE-CYCLE CALLBACKS:
    // onLoad () {}
    Home.prototype.start = function () {
    };
    // update (dt) {}
    Home.prototype.onBtnClick = function () {
        var _this = this;
        cc.loader.loadRes("1_" + this.curr.toFixed(), cc.SpriteFrame, function (err, frame) {
            if (err) {
                cc.error(err);
            }
            else {
                _this.image.spriteFrame = frame;
                _this.scheduleOnce(function () {
                    if (_this.camera.targetTexture) {
                        _this.camera.targetTexture.destroy();
                    }
                    _this.renderTexture = new cc.RenderTexture();
                    _this.renderTexture.packable = false;
                    _this.renderTexture.initWithSize(_this.image.node.width, _this.image.node.height, cc.gfx.RB_FMT_S8);
                    _this.camera.targetTexture = _this.renderTexture;
                    _this.scheduleOnce(function () {
                        _this.camera.render(_this.image.node);
                        var data = _this.renderTexture.readPixels();
                        var targetTex = new cc.RenderTexture();
                        targetTex.packable = false;
                        targetTex.initWithSize(580, 670);
                        targetTex.initWithData(Uint8Array.from(data), cc.Texture2D.PixelFormat.RGBA8888, 580, 670);
                        _this.targetsp.spriteFrame = new cc.SpriteFrame(targetTex);
                    });
                });
            }
        });
        this.curr += 1;
        this.curr = Math.round(this.curr % 3);
    };
    __decorate([
        property(cc.Camera)
    ], Home.prototype, "camera", void 0);
    __decorate([
        property(cc.Sprite)
    ], Home.prototype, "targetsp", void 0);
    __decorate([
        property(cc.Sprite)
    ], Home.prototype, "image", void 0);
    Home = __decorate([
        ccclass
    ], Home);
    return Home;
}(cc.Component));
exports.default = Home;

cc._RF.pop();