// Learn TypeScript: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html import { SofaColor, SofaDir } from "../EventName/EventName"; import AudioManager from "../GameUI/AudioManager"; import Down from "../GameUI/Down"; import RoleQueue from "./RoleQueue"; import Sofa from "./Sofa"; import BarrierDrag from "./barrierDrag"; const { ccclass, property } = cc._decorator; @ccclass export default class Role extends cc.Component { @property(sp.SkeletonData) Zhengmian: sp.SkeletonData = null @property(sp.SkeletonData) BeiMian: sp.SkeletonData = null @property(sp.SkeletonData) CeMian: sp.SkeletonData = null MysPsKeleton: sp.Skeleton = null MyColor: SofaColor start() { } setColor() { switch (this.MyColor) { case SofaColor.蓝: this.MysPsKeleton.setSkin('蓝') break; case SofaColor.灰: console.log('没有这个灰色颜色的人物'); break; case SofaColor.粉: this.MysPsKeleton.setSkin('粉') break; case SofaColor.红: this.MysPsKeleton.setSkin('红') break; case SofaColor.黄: this.MysPsKeleton.setSkin('黄') break; default: break; } } init(RoleColor: SofaColor) { this.MysPsKeleton = this.node.getComponent(sp.Skeleton) this.MyColor = RoleColor this.setColor() //待机_站 待机_坐 坐 走路 this.MysPsKeleton.setAnimation(0, '待机_站', true) } SofaComponent: Sofa //坐下 SitDown(SubData: { x: number, y: number, isleft: number, slefNode: cc.Node }) { // console.log('坐下了得到'); this.SofaComponent = SubData.slefNode.getComponent(Sofa) //切换父节点 自身位置修改 let pos = SubData.slefNode.convertToNodeSpaceAR(this.node.convertToWorldSpaceAR(cc.v2(0, 0))) this.node.parent = SubData.slefNode this.node.setSiblingIndex(0) this.node.setPosition(pos) //执行并且得到入座时间 let JumpSitDownTime = this.getRoleAnim().time let targetPos = cc.v3(0, 0) switch (SubData.isleft) { case 0: //单人 // targetPos =cc.v3(0, 0) break; case 1: //双人左 // targetPos =cc.v3(0, 0) break; case 2: //双人右 targetPos = cc.v3(77, 0) break; default: break; } cc.tween(this.node) .to(JumpSitDownTime * 0.85 * 0.5, { position: targetPos }) // .to(JumpSitDownTime, { position: targetPos }, { easing: dt => cc.easeBounceIn().easing(dt) }) .call(() => { AudioManager.instance.playEffect(AudioManager.BUTTON_EFFECT1) RoleQueue.SitdownRole++ this.SofaComponent.isLock = false this.SofaComponent.NodeBarrierDragComp.ShowLock() switch (SubData.isleft) { case 0: //单人 this.SofaComponent.isTarget[0] = false break; case 1: //双人左 this.SofaComponent.isTarget[0] = false break; case 2: //双人右 this.SofaComponent.isTarget[1] = false break; default: break; } }) .start() } //弹射 NowSitDowAni(targetNode: cc.Node, isleft: number, SeatColor: SofaColor, Sofadir: SofaDir) { this.SofaComponent = targetNode.getComponent(Sofa) Down.NowJumping = false let pos = targetNode.convertToNodeSpaceAR(this.node.convertToWorldSpaceAR(cc.v2(0, 0))) this.node.parent = targetNode this.node.setSiblingIndex(0) this.node.setPosition(pos) let time = 0 let dddd = this.MysPsKeleton.setAnimation(0, '弹射', false) time = dddd.animationEnd this.scheduleOnce(() => { if (this.node.isValid) { let time1 = 0 if (Sofadir == SofaDir.反) { this.MysPsKeleton.skeletonData = this.BeiMian } else { this.MysPsKeleton.skeletonData = this.Zhengmian } this.setColor() time1 = this.MysPsKeleton.setAnimation(0, '弹射', false).animationEnd this.scheduleOnce(() => { this.setColor() time1 = this.MysPsKeleton.setAnimation(0, '待机_坐', true).animationEnd }, time1) } }, time) let pos1 //实际坐在哪个位置 let downseatIndex = 0 switch (isleft) { case 0: //单人 this.SofaComponent.isTarget[0] = true this.SofaComponent.SofaSitDown[0] = 1 pos1 = cc.v2(0, 0) downseatIndex = 0 break; case 1: //双人左 if (this.SofaComponent.SofaSitDown[0] == 0) { this.SofaComponent.isTarget[0] = true this.SofaComponent.SofaSitDown[0] = 1 pos1 = cc.v2(0, 0) downseatIndex = 1 } else { this.SofaComponent.isTarget[1] = true this.SofaComponent.SofaSitDown[1] = 1 pos1 = cc.v2(77, 0) downseatIndex = 2 } break; case 2: //双人右 if (this.SofaComponent.SofaSitDown[1] == 0) { this.SofaComponent.isTarget[1] = true this.SofaComponent.SofaSitDown[1] = 1 pos1 = cc.v2(77, 0) downseatIndex = 2 } else { this.SofaComponent.isTarget[0] = true this.SofaComponent.SofaSitDown[0] = 1 pos1 = cc.v2(0, 0) downseatIndex = 1 } break; default: break; } this.scheduleOnce(() => { cc.tween(this.node) .to(1.26, { position: pos1 }, { easing: 'sineOut' }) .call(() => { AudioManager.instance.playEffect(AudioManager.BUTTON_EFFECT1) RoleQueue.SitdownRole++ switch (downseatIndex) { case 0: //单人 this.SofaComponent.isTarget[0] = false break; case 1: //双人左 this.SofaComponent.isTarget[0] = false break; case 2: //双人右 this.SofaComponent.isTarget[1] = false break; default: break; } this.SofaComponent.isLock = false this.SofaComponent.NodeBarrierDragComp.ShowLock() }) .start() }, 0.06) } getRoleAnim() { let time = 0 if (this.SofaComponent.NodeBarrierDragComp.MyisDouble()) { if (this.SofaComponent.Sofadir === SofaDir.正) { // console.log('zheng'); this.MysPsKeleton.skeletonData = this.Zhengmian this.MysPsKeleton.timeScale = 2 this.setColor() let dddd = this.MysPsKeleton.setAnimation(0, '坐', false) time = dddd.animationEnd this.scheduleOnce(() => { if (this.node.isValid) { this.MysPsKeleton.setAnimation(0, '待机_坐', true) } }, time) } else { // console.log('fan'); this.MysPsKeleton.skeletonData = this.BeiMian this.MysPsKeleton.timeScale = 2 this.setColor() let dddd = this.MysPsKeleton.setAnimation(0, '坐', false) time = dddd.animationEnd this.scheduleOnce(() => { if (this.node.isValid) { this.MysPsKeleton.setAnimation(0, '待机_坐', true) } }, time) } } else { if (this.SofaComponent.Sofadir === SofaDir.正) { // console.log('zheng'); this.MysPsKeleton.skeletonData = this.Zhengmian this.MysPsKeleton.timeScale = 2 this.setColor() let dddd = this.MysPsKeleton.setAnimation(0, '坐', false) time = dddd.animationEnd this.scheduleOnce(() => { if (this.node.isValid) { this.MysPsKeleton.setAnimation(0, '待机_坐', true) } }, time) } else { // console.log('fan'); this.MysPsKeleton.skeletonData = this.BeiMian this.MysPsKeleton.timeScale = 2 this.setColor() let dddd = this.MysPsKeleton.setAnimation(0, '坐', false) time = dddd.animationEnd this.scheduleOnce(() => { if (this.node.isValid) { this.MysPsKeleton.setAnimation(0, '待机_坐', true) } }, time) } } return { time } } // update (dt) {} lastDir: string = '' //坐下 setRoleAnimbyRun(dir: string) { if (this.lastDir == dir) { return } switch (dir) { case '左': this.MysPsKeleton.skeletonData = this.CeMian this.setColor() this.node.scaleX = -0.2 this.MysPsKeleton.setAnimation(0, '走路', true) break; case '右': this.MysPsKeleton.skeletonData = this.CeMian this.setColor() this.node.scaleX = 0.2 this.MysPsKeleton.setAnimation(0, '走路', true) break; case '上': this.MysPsKeleton.skeletonData = this.Zhengmian this.setColor() this.node.scaleX = 0.2 this.MysPsKeleton.setAnimation(0, '走路', true) break; case '下': this.MysPsKeleton.skeletonData = this.BeiMian this.setColor() this.node.scaleX = 0.2 this.MysPsKeleton.setAnimation(0, '走路', true) break; default: break; } this.lastDir = dir } run(dir: string) { switch (dir) { case '上': this.MysPsKeleton.skeletonData = this.Zhengmian this.setColor() this.node.scaleX = 0.2 this.MysPsKeleton.setAnimation(0, '走路', true) break; case '下': this.MysPsKeleton.skeletonData = this.BeiMian this.setColor() this.node.scaleX = 0.2 this.MysPsKeleton.setAnimation(0, '走路', true) break; default: break; } } idle(dir: string) { switch (dir) { case '上': this.MysPsKeleton.skeletonData = this.Zhengmian this.setColor() this.node.scaleX = 0.2 this.MysPsKeleton.setAnimation(0, '待机_站', true) break; case '下': this.MysPsKeleton.skeletonData = this.BeiMian this.setColor() this.node.scaleX = 0.2 this.MysPsKeleton.setAnimation(0, '待机_站', true) break; default: break; } } //队伍第一站立 QueueFirstIdle(isRightQueue: boolean) { //如果是右边的队列 this.MysPsKeleton.skeletonData = this.CeMian this.setColor() if (isRightQueue == true) { this.node.scaleX = -0.2 } else { // console.log(isRightQueue); this.node.scaleX = 0.2 } this.MysPsKeleton.setAnimation(0, '眨眼', true) } //其他人 QueueotherIdle(isRightQueue: boolean) { //如果是右边的队列 if (isRightQueue == false) { this.MysPsKeleton.skeletonData = this.BeiMian this.setColor() this.MysPsKeleton.setAnimation(0, '待机_站', true) } else { this.MysPsKeleton.skeletonData = this.Zhengmian this.setColor() this.MysPsKeleton.setAnimation(0, '待机_站', true) } } }