| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- // 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: {
- Hero: {
- // ATTRIBUTES:
- default: null, // The default value will be used only when the component attaching
- // to a node for the first time
- type: cc.Node, // optional, default is typeof default
- serializable: true, // optional, default is true
- },
- layout : {
- default: null, // The default value will be used only when the component attaching
- // to a node for the first time
- type: cc.Node
- },
- tagDistance : false,
- //0 跳远 1 标枪
- type : 0,
- // bar: {
- // get () {
- // return this._bar;
- // },
- // set (value) {
- // this._bar = value;
- // }
- // },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad : function () {
- this.count = this.layout.getChildByName("layoutcount").getChildByName("count");
- this.layoutcount = this.layout.getChildByName("layoutcount");
- this.updateNum = 0;
- this.layoutcount.active = false;
- this.offsets = [
- 2.36,0.72
- ];
- },
- // start () {
- //
- // },
- startDistance : function (type,b) {
- this.type = type;
- this.tagDistance = b;
- var p = this.Hero.getPosition();
- if (!b) {
- this.updateNum = 0;
- // CustomLog("记录位置 结束 X",p.x);
- setTimeout(function () {
- this.layoutcount.active = false;
- if (this.callBack!=null) {
- var Label = this.count.getComponent("cc.Label");
- this.callBack(Label.string);
- }
- }.bind(this),3000);
- }
- else{
- // CustomLog("记录位置",p.x);
- this.defaultX = p.x;
- this.layoutcount.active = true;
- }
- },
- callBack : function () {
- },
- /**
- * 谁想知道结果 就谁调用这个方法 获取距离的方法
- * @param callBack
- */
- setCallBack : function (callBack) {
- this.callBack = callBack;
- },
- update : function (dt) {
- if (this.tagDistance) {
- var p = this.Hero.getPosition();
- // CustomLog("记录位置",p.x);
- if (this.defaultX != null) {
- this.calculationX = p.x - this.defaultX;
- var showX = this.calculationX/100/this.offsets[this.type];
- var Label = this.count.getComponent("cc.Label");
- Label.string = showX.toFixed(2);
- CustomLog("偏移量 X",showX);
- }
- if (this.updateNum == 0) {
- // CustomLog("记录位置 开始 X",p.x);
- }
- this.updateNum++;
- }
- }
- });
|