// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // camera: {
        //     default: null,
        //     type: cc.Node
        // },
        // bg: {
        //     default: null,
        //     type: cc.Node
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.MainCamera = UtilsNode.getNode("Main Camera",this.node);
        app.camera = this.MainCamera;
    },

    start() {



       this.bg = UtilsNode.getNode("bg",this.node);

        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onkeyUp, this);
        this.wTag = false;
        this.sTag = false;


        // let MoveUp = cc.moveBy(0.5,cc.v2(0,1000)).easing(cc.easeIn(10));
    },

    onkeyUp: function (event) {
        switch(event.keyCode) {
            case cc.macro.KEY.w:
                console.log('Press a key');
                this.wTag = false;
                break;
            case cc.macro.KEY.s:
                console.log('Press a key');
                this.sTag = false;
                break;
        }
    },

    onKeyDown: function (event) {
        switch(event.keyCode) {
            case cc.macro.KEY.w:
                console.log('Press a key');
                this.wTag = true;
                break;
            case cc.macro.KEY.s:
                console.log('Press a key');
                this.sTag = true;
                break;
        }
    },
    update (dt) {
        if (this.wTag) {
            this.MainCamera.y -=40;
            // this.camera.getComponent(cc.Camera).zoomRatio+=1;
        }else if (this.sTag) {
            this.MainCamera.y +=40;
            // this.camera.getComponent(cc.Camera).zoomRatio-=1;
        }
    },
});
