var Base = cc.Class({
  extends: cc.Component,
  properties: {
    root_view: { default: null, type: cc.Node }
  },
  statics: {
    callback_message: "",
    default_width: 1920,
    default_height: 1080
  },

  update: function(dt) {}
});
//设置屏幕宽度比例
window.setScaleX = function(view) {
  let windowSize = cc.winSize; //推荐  原因  短
  let width = windowSize.width;
  let scale_x = width / Base.default_width;
  view.scaleX = scale_x;
};

//设置view的触摸方法
window.setViewTouch = function(
  view,
  touch_start,
  touch_end,
  touch_cancel,
  context
) {
  if (!touch_start) {
    //touch_start是undefined、null和空字符串中的一种
    view.node.on(
      cc.Node.EventType.TOUCH_START,
      function(event) {
        // view.node.color = new cc.color(112, 80, 80, 80);
      },
      context
    );
  } else {
    view.node.on(cc.Node.EventType.TOUCH_START, touch_start, context);
  }

  if (!touch_end) {
    //touch_end是undefined、null和空字符串中的一种
    view.node.on(
      cc.Node.EventType.touch_end,
      function(event) {
        // view.node.color = new cc.color(80, 100, 100, 100);
      },
      context
    );
  } else {
    view.node.on(cc.Node.EventType.TOUCH_END, touch_end, context);
  }

  if (!touch_cancel) {
    //touch_end是undefined、null和空字符串中的一种
    view.node.on(
      cc.Node.EventType.TOUCH_CANCEL,
      function(event) {
        // view.node.color = new cc.color(80, 100, 100, 100);
      },
      context
    );
  } else {
    view.node.on(cc.Node.EventType.TOUCH_CANCEL, touch_cancel, context);
  }
};
//android回调方法
window.onCallBack = function(message) {
  if (cc.sys.OS_ANDROID == cc.sys.os) {
    Base.callback_message = message;
    callAndroidString("LogE", Base.callback_message);
  }
};

window.callAndroidString = function(method_name, params_json) {
  if (cc.sys.OS_ANDROID == cc.sys.os) {
    jsb.reflection.callStaticMethod(
      "org/cocos2dx/javascript/CallAndroid",
      method_name,
      "(Ljava/lang/String;)V",
      params_json
    );
  }
};

window.callAndroidVoid = function(method_name) {
  if (cc.sys.OS_ANDROID == cc.sys.os) {
    jsb.reflection.callStaticMethod(
      "org/cocos2dx/javascript/CallAndroid",
      method_name,
      "()V"
    );
  }
};
