import EventMgr from "../../../../FrameWork/Event/EventMgr"; import { ryw_Event } from "../../../../FrameWork/Event/EventEnum"; import Common5 from "../../../../Platform/th/Common5"; import Common from "../../../../FrameWork/Util/Common"; import DaDianScript from "../../../../FrameWork/Base/DaDianScript"; import WordGameBaseComponent from "../../../../FrameWork/Base/WordGameBaseComptent"; import Game from "../../../../Scripts/WenZiRes/ui/Game"; const {ccclass, property} = cc._decorator; enum TimeStatus{ GuoQu, WeiLai } let CurGameConfig = { CheckNode:[ 'ck_背景','ck_雪爷爷','ck_破衣爷爷1','ck_椅子1','ck_奶奶','ck_木门','ck_猪','ck_烤架','ck_红薯','ck_垃圾','ck_脸盆','ck_木盆','ck_全家福' ], XianZaiTexture:[ 'q_背景','q_雪爷爷spine','h_破衣爷爷spine','h_穿衣爷爷1','q_奶奶spine','q_门spine','q_猪','q_烤架','q_红薯','q_可动垃圾','q_脸盆','q_木盆','q_全家福' ], WeiLaiTexture:[ 'h_背景','h_破衣爷爷spine','','h_按摩椅1','h_老奶奶','h_门','h_猪','h_燃气灶','h_烤乳猪','h_冰箱','h_洗手盆','h_洗衣机','h_小孩' ], WeiLaiAudio:[ '终于住上新房子了','住不上雪屋了,怪可惜的','新衣服就是好啊','这高科技的椅子就是舒服', '没想到老婆子一打扮还挺好看','终于不漏风了','来年有猪肉吃了','还是这个烤着方便','家里唯一的猪仔啊,就被你这个老太婆烤了', '这是给我准备的吗','热水洗脸就是舒服','解放双手了','奶奶,我来看你了' ] } @ccclass export default class KongChaoLaoRen extends WordGameBaseComponent{ @property(cc.Node) maskNode:cc.Node = null; @property(cc.Node) mapNode:cc.Node = null; gameInfo = null bundle = null mapNodeFixedScale:number = 0.6//固定缩放(图片太大了) touchStartTime:number = 0//触摸开始时间 originalTouchDistance:number = 0 //起始双指触摸间距 lastScale:number = 1//上次缩放值 curScale:number = 1//当前缩放值 touchId1:number = -1 touchId2:number = -2 curFinishNum:number = 0 isStepRight:boolean = true isKaiMen:boolean = false isHuanMen:boolean = false isHuanZhu:boolean = false isChuangYi:boolean = false isHuanYiZi:boolean = false onLoad(){ DaDianScript.userEnterDaDian() Common.Type = 0; Common.subLevel = 0; Common.GameSubTipConfigs=[Common5.gameConfig.zmGameConfig[Common5.selectGameNum].toolTip] Common.GameSubAnswerConfigs=[Common5.gameConfig.zmGameConfig[Common5.selectGameNum].answer] this.bundle = Common5.gameConfig.zmGameConfig[Common5.selectGameNum].bundle EventMgr.onEvent_custom(ryw_Event.timeOut, (tab) => { Game.ins.showFail();; }, this); EventMgr.onEvent_custom(ryw_Event.DirectTouchMoveCheck, (data_) => { if(data_.targetNode.name == 'touchNodeMen'){ this.isKaiMen = true if(this.isHuanMen){ this.mapNode.getChildByName('好门开').active = true this.mapNode.getChildByName('h_门').active = false this.mapNode.getChildByName('h_门spine').active = false } } }, this); } start(){ super.start(); cc.macro.ENABLE_MULTI_TOUCH = true; this.initMapNodeTouchEvent() } //初始化触摸监听 initMapNodeTouchEvent(){ this.initMouseEvent(); this.mapNode.on(cc.Node.EventType.TOUCH_START, this.touchStart_mapNode,this) this.mapNode.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove_mapNode,this) this.mapNode.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd_mapNode,this) this.mapNode.on(cc.Node.EventType.TOUCH_END, this.touchEnd_mapNode,this) let prefabWidth = this.mapNode.width let prefabHeight = this.mapNode.height let maskWidth = this.maskNode.width let maskHeight = this.maskNode.height let widthScale = maskWidth/prefabWidth let heightScale = maskHeight/prefabHeight if(prefabWidth= 0 && this.touchId2 >= 0){ // console.log("邵阳1—双点触摸开始") } this.touchStartTime = Date.now() } touchMove_mapNode(event){ let touches = event.getTouches() if(touches.length == 2){ //缩放 if(this.originalTouchDistance == 0){ this.originalTouchDistance = this.getDistance(touches[0].getLocation(),touches[1].getLocation()) } //获取双指移动数据 let curDistance = this.getDistance(touches[0].getLocation(),touches[1].getLocation()) let tempScale = curDistance/this.originalTouchDistance let y = 0.5*tempScale + 0.5 let scale = y * this.lastScale if(scale < this.mapNodeFixedScale){ scale = this.mapNodeFixedScale }else if(scale > 3){ scale = 3 }else{ } this.mapNode.scale = scale this.curScale = scale this.goToBoundary(); }else if(touches.length == 1){ //拖动 let delta = event.getDelta() this.mapNode.x += delta.x this.mapNode.y += delta.y // console.log(this.mapNode.scale,this.mapNode.x,this.mapNode.y); this.goToBoundary() } } touchEnd_mapNode(event){ console.log('touchEnd===') let dateNow = Date.now() if(dateNow - this.touchStartTime > 0.2 * 1000){ // console.log('0.2===') // //补丁,长按两秒 // if(dateNow - this.touchStartTime > 1.5 * 1000){ // console.log('2===') // let wl_fangzi = this.mapNode.getChildByName('wl_房子') // let chuanghuguan = wl_fangzi.getChildByName('窗户关') // let chuanghukai = wl_fangzi.getChildByName('窗户开') // let rect = chuanghuguan.getBoundingBoxToWorld() // if(wl_fangzi.active && chuanghuguan.active && rect.contains(event.getLocation())){ // chuanghuguan.active = false // chuanghukai.active = true // this.isKaiChuang = true // } // } }else{ // this.isFind = false; let touchPos = event.getLocation(); this.checkIsInAreaNewVersion(touchPos) } if(event.touch.getID() == this.touchId1){ this.touchId1 = -1 }else if(event.touch.getID() == this.touchId2){ this.touchId2 = -2 } if(this.touchId1 < 0 && this.touchId2 < 0){ this.originalTouchDistance = 0 this.lastScale = this.curScale // this.goToBoundary() } } //距离 getDistance(startPos,endPos){ var pos = cc.v2(startPos.x - endPos.x,startPos.y - endPos.y) var dis = Math.sqrt(pos.x * pos.x + pos.y * pos.y) return dis } //检测边界 goToBoundary(){ let widthMask = this.maskNode.width let heightMask = this.maskNode.height let widthMap = this.mapNode.width*this.curScale let heightMap = this.mapNode.height*this.curScale //右边界 if(this.mapNode.x + widthMap/2 <= widthMask/2){ this.mapNode.x = widthMask/2 - widthMap/2 //左边界 }else if(this.mapNode.x - widthMap/2>= -widthMask/2){ this.mapNode.x = -widthMask/2 + widthMap/2 } //上边界 if(this.mapNode.y + heightMap/2 <= heightMask/2){ this.mapNode.y = heightMask/2 - heightMap/2 //下边界 }else if(this.mapNode.y - heightMap/2 >= -heightMask/2){ this.mapNode.y = -heightMask/2 + heightMap/2 } } initMouseEvent(){ this.mapNode.on(cc.Node.EventType.MOUSE_WHEEL,function(event){//监听名称+事件参数 console.log(event); let tmpscale = this.mapNode.scale; if (event._scrollY > 0){ if (this.mapNode.scale < 3){ tmpscale+=0.2; this.mapNode.scale = tmpscale this.curScale = tmpscale this.lastScale = tmpscale } } else { if (this.mapNode.scale > this.mapNodeFixedScale){ tmpscale-=0.2; this.mapNode.scale = tmpscale this.curScale = tmpscale this.lastScale = tmpscale } } // console.log(this.mapNode.scale,this.mapNode.x,this.mapNode.y); this.goToBoundary(); },this); } //检测node是否进入target区域(新版) checkIsInAreaNewVersion(pos){ // //茬点触碰逻辑 // let childrens = this.mapNode.getChildByName("chaDianNode").children // for(var i =0;i= 0) { this.curFinishNum ++ this.checkIsFinish(true) this.showDuiHua(CurGameConfig.WeiLaiAudio[checkIndex]) this.closeTouchEvent(event.target) event.target.active = false let changeNode1 = this.mapNode.getChildByName(target.changeNodeTab1[checkIndex]) if(changeNode1){ changeNode1.active = false } let changeNode2 = this.mapNode.getChildByName(target.changeNodeTab2[checkIndex]) if(changeNode2){ changeNode2.active = true } let checkNode = this.mapNode.getChildByName(target.checkNodeTab[checkIndex]) if(checkNode){ checkNode.active = false } }else{ event.target.setPosition(event.target.startPos) } } checkArea(node,checkNodeTab){ let checkIndex = -1 for(let i=0;i= 13){ this.scheduleOnce(()=>{ Game.ins.showSuccess() },2) } } showDuiHua(str, func?) { console.log("str==", str) if (!str || str == '') { return; } Common5.playEffectCustom(this.bundle, 'sound/'+str); let qiPao = this.node.getChildByName("duihua") qiPao.stopAllActions() qiPao.getChildByName("tabLab2").getComponent(cc.Label).string = str qiPao.active = true qiPao.scale = 0 cc.tween(qiPao) .to(0.2, { scale: 1 }) .delay(3) .call(() => { qiPao.active = false; if (func) { func(); } }) .start(); } }