const {ccclass, property} = cc._decorator; @ccclass export default class NewClass extends cc.Component { id_Number:number _speed:number _color:number touch:boolean _repeat:boolean move:boolean // onLoad () {} start () { this.node.on(cc.Node.EventType.TOUCH_START, this.clickBtn, this); } //初始化数据 init(_id,color,speed,repeat){ this.touch = true; this.move = false; this.id_Number = _id; this._color = color; this._speed = speed; this._repeat = repeat; //太阳动画 cc.tween(this.node.getChildByName("shan")) .repeatForever( cc.tween() .to(1,{opacity:0,scale:0.5,}) .delay(0.2) .to(1,{opacity:255,scale:1.2}) .delay(0.5) ) .start(); } //用于作弊 测试 showNumber(type){ this.node.getChildByName("number").active = type; if(type == true) this.node.getChildByName("number").getComponent(cc.Label).string = this.id_Number + ""; } //计算两点之间直线距离 distanceBetweenTwoPoints(x1: number, y1: number, x2: number, y2: number): number { return Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2); } //点击事件 clickBtn(event,data){ let pos = this.node.convertToNodeSpaceAR(event.getLocation()); let distance = this.distanceBetweenTwoPoints(pos.x, 0, pos.y, 0); distance = Math.floor(distance*10)/10; if(this.node.name != "qiu4"){ if( this.move == false && this.touch == true){ if(this.node.parent.parent.name == "GameNode"){ if(this.node.parent.parent.getComponent("GameManager").begin == true){ cc.tween(this.node.getChildByName("action")) .to(0.5,{opacity:0,scale:1.8}) .start(); cc.tween(this.node) .to(0.3,{scale:1.3}) .to(0.3,{scale:1}) .start(); this.touch = false; this.node.zIndex = -1; let data = {id:this.id_Number,distance:distance}; cc.fx.Notifications.emit("clickSun",data); } } else{ this.touch = false; this.node.zIndex = -1; let data = {id:this.id_Number,distance:distance}; cc.fx.Notifications.emit("clickSun",data); } } } else{ if( this.touch == true && this.node.parent.parent.getComponent("GuideManager").begin == true){ this.touch = false; this.node.zIndex = -1; let data = {id:this.id_Number,distance:distance}; cc.fx.Notifications.emit("clickSun",data); } } } }