75 lines
2.4 KiB
JavaScript
75 lines
2.4 KiB
JavaScript
// Learn cc.Class:
|
|
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
|
|
// - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
|
|
// Learn Attribute:
|
|
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
|
|
// - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
|
|
// Learn life-cycle callbacks:
|
|
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
|
|
// - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
|
|
var distance = 35//
|
|
var xiuzheng = 25//
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
nd_air: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
nd_tank: {
|
|
default: null,
|
|
type: cc.Node,
|
|
},
|
|
lb_dis: {
|
|
default: null,
|
|
type: cc.Label,
|
|
},
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {},
|
|
|
|
start() {
|
|
|
|
},
|
|
setdata(x, y, isair) {
|
|
|
|
this.ppos = cc.v2(x, y)
|
|
this.nd_air.active = isair
|
|
this.nd_tank.active = !isair
|
|
|
|
|
|
// let pos1 = cc.gameMgr.ndplayer.convertToWorldSpaceAR(this.ppos);
|
|
// this.mappos = this.node.parent.convertToNodeSpaceAR(pos1);
|
|
|
|
},
|
|
|
|
update(dt) {
|
|
var vw = cc.winSize.width / 2 / cc.gameMgr.viewScale
|
|
var vh = cc.winSize.height / 2 / cc.gameMgr.viewScale
|
|
var dx = Math.abs(this.ppos.x-cc.gameMgr.watchPlayer.x)
|
|
var dy = Math.abs(this.ppos.y-cc.gameMgr.watchPlayer.y)
|
|
if(dx<vw && dy<vh){
|
|
this.node.opacity = 1
|
|
}else{
|
|
this.node.opacity = 255
|
|
}
|
|
var dis = Math.sqrt(dx * dx + dy * dy)
|
|
dis = Math.floor(dis/50)
|
|
if(dis>distance){
|
|
this.node.opacity = 1
|
|
}
|
|
this.node.zIndex = -dis
|
|
this.lb_dis.string = dis+"m"
|
|
|
|
let pos1 = cc.gameMgr.ndplayer.convertToWorldSpaceAR(this.ppos);
|
|
this.mappos = this.node.parent.convertToNodeSpaceAR(pos1);
|
|
|
|
this.node.x = this.mappos.x
|
|
this.node.y = this.mappos.y
|
|
this.node.x = Math.max(Math.min(cc.winSize.width / 2 - xiuzheng, this.node.x), -cc.winSize.width / 2 + xiuzheng)
|
|
this.node.y = Math.max(Math.min(cc.winSize.height / 2 - xiuzheng, this.node.y), -cc.winSize.height / 2 + xiuzheng)
|
|
},
|
|
}); |