cc.Class({
    extends: cc.Component,

    properties: {
        sprite:null,
        baseSpriteFrame:cc.SpriteFrame,
        clip:cc.SpriteFrame,
        tex:cc.RenderTexture,
        clipSprite:null,       
    },

    // use this for initialization
    start: function () {
        var size = this.baseSpriteFrame.getOriginalSize ();
        this.tex = cc.RenderTexture.create(size.width,size.height);
        
        var baseSprite = new _ccsg.Sprite(this.baseSpriteFrame);
        this.clipSprite = new _ccsg.Sprite(this.clip);
        this.clipSprite.setBlendFunc(cc.BlendFunc.BlendFactor.ZERO,cc.BlendFunc.BlendFactor.ONE_MINUS_SRC_ALPHA);

        this.tex.begin();
        baseSprite.setPosition(cc.p(size.width/2,size.height/2));
        baseSprite.visit();
        this.tex.end();
        this.node._sgNode.addChild(this.tex);
        this.tex.addChild(this.clipSprite);
        this.clipSprite.setPosition(cc.p(512,512));
        this.clipSprite.visible = false;
        this.tex.begin();
        this.clipSprite.visible = true;
        this.clipSprite.visit();
        this.clipSprite.visible = false;
        this.tex.end();
    },

    // called every frame, uncomment this function to activate update callback
    update: function (dt) {
        this.clipSprite.visible = true;
        this.tex.begin();
        var pos = this.clipSprite.getPosition();
        this.clipSprite.setPosition(pos.x+140*dt,pos.y+140*dt);
        // this.clipSprite.x += 140*dt;
        // this.clipSprite.y += 140*dt;

        this.clipSprite.visit();

        this.tex.end();
        this.clipSprite.visible = false;
    },
});
