
cc.Class({
    extends: cc.Component,

    properties: {
        camera: {
            default: null,
            type: cc.Node
        },
        root: {
            default: null,
            type: cc.Node
        },
        moveSpeed: 100,
        _useCamera: true,
        useCamera: {
            get: function () {
                return this._useCamera;
            },
            set: function (v) {
                if (this._useCamera === v) return;

                this._useCamera = v;

                if (!CC_EDITOR && this.movingNode) {
                    this.movingNode = v ? this.camera : this.root;
                    this.camera.x = this.root.x = 0;
                    this.moveSpeed = -this.moveSpeed;
                }
            }
        },
        _enableCulling: true,
        enableCulling: {
            get: function () {
                return this._enableCulling;
            },
            set: function (v) {
                this._enableCulling = v;
                this.setMacroCulling(v);
            }
        }
    },

    onLoad () {
        this.movingNode = this._useCamera ? this.camera : this.root;
        
        this.setMacroCulling(this._enableCulling);

        this.node.on(cc.Node.EventType.TOUCH_MOVE, event => {
            let posY = event.getLocationY()
            let delta = event.getDelta()
            this.movingNode.y -= delta.y;
            console.log(delta);
        }, this)
    },

    start () {

    },

    onEnable: function () {
        this._originEnableCulling = cc.macro.ENABLE_CULLING;
    },

    onDisable: function () {
        this.setMacroCulling(this._originEnableCulling);
    },

    setMacroCulling: function (enable) {
        if (cc.macro.ENABLE_CULLING === enable || CC_JSB) return;

        cc.macro.ENABLE_CULLING = enable;
        cc.renderer.childrenOrderDirty = true;
    },

    update (dt) {
        // this.movingNode.y += this.moveSpeed * dt;
        // if ((this.moveSpeed > 0 && this.movingNode.y > 1600) || 
        //     (this.moveSpeed < 0 && this.movingNode.y < -1600)) {
        //     this.moveSpeed *= -1;
        // }
    },
});
