const constants = require('Constants'); cc.Class({ extends: cc.Component, properties: { ArmatureDisPlay:null, AnimationsNameArr:[], AnimPlayScript:null, PlayerControlScript:null, PlayerStatesScript:null, DragonBonesAsset:null, LastSpeedLevel:0, IsSlowingDownSpeed:false, }, start () { this.Init(); }, Init:function(){ this.AnimPlayScript = this.node.getComponent('AnimPlay'); this.ArmatureDisPlay = this.getComponent(dragonBones.ArmatureDisplay); this.DragonBonesAsset = this.ArmatureDisPlay.dragonAsset; this.AnimPlayScript.ArmatureDisPlay = this.ArmatureDisPlay; this.SetArmatureName('Female'); this.AnimAddEventListener(); this.PlayerStatesScript = GlobalData.game.getHeroControl().getComponent('PlayerStates'); cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);//测试数据 }, testLog:function(){ var a = JSON.parse(this.DragonBonesAsset.dragonBonesJson); cc.log(a.frameRate+'*****'); }, GetSpeedLevel:function(SpeedMin){ if(SpeedMin){ var a = constants.configGameSpeedMax/6; var b = Math.floor(SpeedMin/a); return b; }else{ var a = constants.configGameSpeedMax/6; var b = Math.floor(GlobalData.game.GameSpeed/a); return b; } }, /** * ArmatureName = 'Female' or 'Jav' or 'Mammoth' * **/ SetArmatureName:function(ArmatureName){ this.ArmatureDisPlay.armatureName = ArmatureName; }, onKeyDown: function (event) {//测试数据 switch (event.keyCode) { case cc.KEY.a: cc.log('Press a '); this.AnimPlayScript.PlayIdleAnim(); break; case cc.KEY.s: cc.log('Press s'); this.AnimPlayScript.PlayFemaleRunAnim(1); break; case cc.KEY.d: cc.log('Press d'); this.AnimPlayScript.PlayLongJumpDownAnim(); this.AddAnimFadeInListener(); break; } }, // update(dt){ // // }, /** * 以下动画骨骼为Female * **/ /* * this.PlayerStatesScript.PlayerStates = 'NormalRun'or'HoldJavelinRun'or'RideElephantRun'or'Over', * */ //加速 SpeedChange:function(){ if(this.PlayerStatesScript.strPlayerStates == 'NormalRun'){ this.AnimPlayScript.PlayFemaleRunAnim(this.GetSpeedLevel(),0); }else if(this.PlayerStatesScript.strPlayerStates == 'HoldJavelinRun'){ this.AnimPlayScript.PlayJavelinRunAnim(this.GetSpeedLevel(),0); }else if(this.PlayerStatesScript.strPlayerStates == 'RideElephantRun'){ this.AnimPlayScript.PlayRideElephantRunAnim(this.GetSpeedLevel(),0); }else{ cc.log(this.PlayerStatesScript.strPlayerStates); } this.ArmatureDisPlay.timeScale = 1; }, //减速 SlowingDownSpeed:function(SpeedLevel,PlayTimes){ if(this.PlayerStatesScript.strPlayerStates == 'NormalRun'){ this.AnimPlayScript.PlayFemaleRunAnim(SpeedLevel,PlayTimes); }else if(this.PlayerStatesScript.strPlayerStates == 'HoldJavelinRun'){ this.AnimPlayScript.PlayJavelinRunAnim(SpeedLevel,PlayTimes); }else if(this.PlayerStatesScript.strPlayerStates == 'RideElephantRun'){ this.AnimPlayScript.PlayRideElephantRunAnim(SpeedLevel,PlayTimes); }else{ cc.log(this.PlayerStatesScript.strPlayerStates); } this.ArmatureDisPlay.timeScale = 1; this.setEndListener(function (name) { if(this.LastSpeedLevel>1){ this.LastSpeedLevel-=1; this.SlowingDownSpeed(this.LastSpeedLevel,1); }else if(this.LastSpeedLevel == 1){ this.SlowingDownSpeed(1,0); } }.bind(this)); }, //减速前的判断.目前是项目结束的地方调用。由于是每帧调用,所以需要加个判断,不能让动画不断重播 JudgeBeforeSpeedChange:function(){ if(this.IsSlowingDownSpeed == false){ this.IsSlowingDownSpeed = true; this.LastSpeedLevel = this.GetSpeedLevel(); this.SlowingDownSpeed(this.LastSpeedLevel,1); } }, //摔倒 Stagger:function(){ if(this.PlayerStatesScript.strPlayerStates == 'NormalRun'){ this.AnimPlayScript.PlayFemaleFallAnim(); }else if(this.PlayerStatesScript.strPlayerStates == 'HoldJavelinRun'){ this.AnimPlayScript.PlayJavelinFallAnim(); }else if(this.PlayerStatesScript.strPlayerStates == 'RideElephantRun'){ this.AnimPlayScript.PlayElephantFallAnim(); } }, //空闲 Idle:function(){ this.AnimPlayScript.PlayIdleAnim(); }, //跨栏 JumpToHurdle:function(){ this.AnimPlayScript.PlayHurdleJumpAnim(); }, //扔标枪 ThrowJavelinOut:function(){ this.AnimPlayScript.PlayJavelinOutAnim(); }, //跳远起跳 LongJumpUp:function(jumpTimer){ this.AnimPlayScript.PlayLongJumpUpAnim(); this.ArmatureDisPlay.timeScale = 1/jumpTimer; }, //跳远落地 LongJumpDown:function(jumpTimer){ this.AnimPlayScript.PlayLongJumpDownAnim(); this.ArmatureDisPlay.timeScale = 1/jumpTimer; }, //跳上大象 JumpOnElephant:function(){ this.AnimPlayScript.PlayUpElephantAnim(); }, //跳下大象 JumpOutElephant:function(){ this.AnimPlayScript.PlayElephantOutAnim(); }, /** * 以下动画骨骼为Jav * **/ //标枪飞行及落地 JavelinFlyToDown:function(){ this.AnimPlayScript.PlayJavelinFlyAnim(); }, /** * 以下动画骨骼为Mammoth * **/ //大象跑步动画 ElephantRun:function(){ this.AnimPlayScript.PlayElephantRunAnim(); }, //============================================= AnimAddEventListener:function(){ this.ArmatureDisPlay.addEventListener(dragonBones.EventObject.START, this._animationEventHandler, this); this.ArmatureDisPlay.addEventListener(dragonBones.EventObject.COMPLETE, this._animationEventHandler, this) }, _animationEventHandler: function(event) { if (event.type === dragonBones.EventObject.START) { if (event.detail.animationState.name === "JavFly") { // this._armature.animation.fadeIn("jump_2", -1, -1, 0, NORMAL_ANIMATION_GROUP); } else if (event.detail.animationState.name === "jump_4") { this._updateAnimation(); } } else if (event.type === dragonBones.EventObject.COMPLETE) { // cc.log('animationName is '+event.detail.animationState.name); if(GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates == 'Over'){ return; }else{ // cc.log('strPlayerStates is '+GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates); } if (this.endListener!=null){ this.endListener(event.detail.animationState.name); } if (event.detail.animationState.name === "JavFly") { this.AnimPlayScript.PlayJavelinDownAnim();//标枪在空中飞行完成后,播放落地动画 }else if(event.detail.animationState.name === "FemaleSpan"){ this.AnimPlayScript.PlayFemaleRunAnim(this.GetSpeedLevel());//跨栏落地后,继续跑 }else if(event.detail.animationState.name === "FemaleJavOut"){ this.AnimPlayScript.PlayIdleAnim();//扔出标枪后,闲置 }else if(event.detail.animationState.name === "FAnimalUp"){ this.AnimPlayScript.PlayRideElephantRunAnim(this.GetSpeedLevel(),0);//跳上大象后,开跑 }else if(event.detail.animationState.name === "FAnimalOut"){ this.AnimPlayScript.PlayFemaleRunAnim(this.GetSpeedLevel(),0);//跳下大象后,单人跑 } } }, _updateAnimation:function () { }, setEndListener: function (endListener) { this.endListener = endListener; }, endListener: function () { var a = JSON.parse(this.DragonBonesAsset.dragonBonesJson); // cc.log(a.frameRate+'*****'); // cc.log(a.armature[0].animation+'+++++'); }, /** * 以下是animation动画 */ //无敌状态闪烁 PlayPlayerFlashingAnim:function () { var animCtrl = this.getComponent(cc.Animation); animCtrl.play("PlayerFlashing"); }, StopPlayerFlashingAnim:function () { var animCtrl = this.getComponent(cc.Animation); animCtrl.stop("PlayerFlashing"); this.node.opacity = 255; }, });