// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html //出现块的类型,问题以及答案 var BlockType = cc.Enum({ problem_In: 1, //内圈问题 problem_Out: 2, //外圈问题 correct_In:3, //内圈正确答案 correct_Out:4, //外圈正确答案 err_In:5, //内圈错误答案 err_Out:6, //外圈错误答案 }); const {ccclass, property} = cc._decorator; @ccclass export default class Block extends cc.Component { @property(cc.Asset) UI: cc.Asset = null; _touch: boolean; _start: boolean; _answer: boolean; _inside: boolean; _idNumber: number; GameManager: any; tube_Array: number[][];//管子数组 // LIFE-CYCLE CALLBACKS: onLoad () { // this.init(); this.GameManager = this.node.parent.parent.parent.getComponent("GameManager"); this._touch = false; this._start = false; this._answer = false; this._inside = true; this.node.on(cc.Node.EventType.TOUCH_START, this.touchStart, this); } init(type,id){ if(type == BlockType.correct_Out){ } } setId(id){ this._idNumber = id; } answerShow(texture){ this.node.getChildByName("texture").active = true; let textureName = "texture"+texture; // @ts-ignore this.node.getChildByName("texture").getComponent(cc.Sprite).spriteFrame = this.UI._spriteFrames[textureName]; cc.tween(this.node.getChildByName("texture")) .to(0.01,{opacity:255}) .delay(this.GameManager.config["showTime"]-0.05) .call(() =>{ if(this._inside){ this.node.getChildByName("texture").opacity = 0; } }) .start(); } lockShow(type,inside){ this.node.getChildByName("texture").active = false; this._answer = type; this._inside = inside; this.node.getChildByName("lock").active = true; this._touch = true; } lockHide(){ this.node.getChildByName("lock").active = false; this._touch = false; } show(type,inside,texture){ // this._answer = type; this._inside = inside; if(inside) this._answer = type; let textureName = "texture"+texture; this.node.getChildByName("texture").active = true; //正确答案 //@ts-ignore this.node.getChildByName("texture").getComponent(cc.Sprite).spriteFrame = this.UI._spriteFrames[textureName]; cc.tween(this.node.getChildByName("texture")) .to(0.01,{opacity:255}) // .delay(this.GameManager.config["showTime"]-0.1) .call(() =>{ if(inside){ this._touch = true; } }) .start(); } set_Pos(){ this._start = true; } set_Touch(type){ this._touch = type; } start () { } //开始点击,提高层级 touchStart (event) { if(this._touch){ if(this._answer){ this.node.getChildByName("yes").active = true; let data = {"result":true,"type":this._inside,id:this._idNumber}; cc.fx.Notifications.emit("result",data); } else{ this.node.getChildByName("err").active = true; let data = {"result":false,"type":this._inside,id:this._idNumber}; cc.fx.Notifications.emit("result",data); } } } // update (dt) { // } }