| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783 |
- const GameStatesStatic = require('GameStates');
- const PlayerState = require('PlayerState');
- const GameProgress = cc.Enum({
- default: 0,
- Race: 1,
- LongJump: 2,
- Hurdle: 3,
- RideBike: 4,
- Javelin: 5,
- });
- cc.Class({
- extends: cc.Component,
- properties: {
- readyRunTag: 0,
- //当前进行的项目
- type: 0,
- Canvas: {
- default: null,
- type: cc.Node
- },
- Hero: null,
- HeroControlScript: null,
- CurrentProgress: {
- default: GameProgress.Race,
- type: cc.Enum(GameProgress)
- },
- },
- onLoad: function () {
- this.Hero = this.node.parent;
- this.HeroControlScript = this.Hero.getComponent('HeroControl');
- cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
- },
- onKeyDown: function (event) {
- switch (event.keyCode) {
- case cc.KEY.a:
- cc.log('Press a key');
- this.walk();
- break;
- case cc.KEY.s:
- cc.log('Press a key');
- this.idleadd2();
- break;
- case cc.KEY.d:
- cc.log('Press a key');
- this.idle();
- break;
- }
- },
- setSkins: function (skinName) {
- //随机皮肤
- this.spine.setSkin(skinName);
- },
- start: function () {
- //获取 ArmatureDisplay
- this.spine = this.getComponent(dragonBones.ArmatureDisplay);
- this.arrAnimation = [];
- //获取 Armatrue
- // this.spine = this.spine.armature()
- //添加动画监听
- this.spine.addEventListener(dragonBones.EventObject.START, this.animationEventHandler, this)
- this.spine.addEventListener(dragonBones.EventObject.COMPLETE, this.animationEventHandler, this)
- var myArmature = this.spine.getArmatureNames();
- var myAnimationNames = this.spine.getAnimationNames(myArmature[0]);
- cc.log("现在 龙骨动作名字", myAnimationNames);
- this.initData();
- this.setType();
- this.idle();
- // this.walkadd();
- // this.idle();
- // this.walkadd();
- // this.idleadd1();
- return;
- var spine = this.spine = this.getComponent('sp.Skeleton');
- // cc.log("现在 播放 骨骼动画对象", spine);
- this._hasStop = true;
- this.setType();
- // .setStartListener()用来设置开始播放动画的事件监听。
- spine.setStartListener(function (trackEntry) {
- var animationName = trackEntry.animation ? trackEntry.animation.name : "";
- // cc.log("[track %s][animation %s] start.", trackEntry.trackIndex, animationName);
- // cc.log("现在 播放 的动画名字是", animationName);
- if (animationName == this.arr[this.type][this.walkLv]) {
- if (this.readyRunTag == 0) {
- }
- this.readyRunTag++;
- // this._hasStop = false;
- }
- this.setStatus(animationName);
- }.bind(this));
- // .setInterruptListener()用来设置动画被打断的事件监听。
- spine.setInterruptListener(function (trackEntry) {
- var animationName = trackEntry.animation ? trackEntry.animation.name : "";
- if (this.interruptListener != null) {
- this.interruptListener(animationName);
- }
- }.bind(this));
- // .setEndListener()用来设置动画播放完后的事件监听。
- spine.setEndListener(function (trackEntry) {
- var animationName = trackEntry.animation ? trackEntry.animation.name : "";
- // cc.log("现在 停止 的动画名字是", animationName);
- if (animationName == this.statusArr[6] || animationName == this.statusArr[5]) {
- }
- if (this.endListener != null) {
- this.endListener(animationName);
- }
- }.bind(this));
- // .setDisposeListener()用来设置动画将被销毁的事件监听。
- spine.setDisposeListener(function (trackEntry) {
- var animationName = trackEntry.animation ? trackEntry.animation.name : "";
- }.bind(this));
- spine.setCompleteListener(function (trackEntry, loopCount) {
- }.bind(this));
- // .setEventListener()用来设置动画播放过程中帧事件的监听。
- spine.setEventListener(function (trackEntry, event) {
- }.bind(this));
- },
- //回调
- animationEventHandler: function(event) {
- switch (event.type){
- case dragonBones.EventObject.START:
- // cc.log(this.spine.animationName , ' START complete');
- break;
- case dragonBones.EventObject.COMPLETE:
- // cc.log(this.spine.animationName , ' 结束的动作');
- // cc.log(this.spine.animationName, ' COMPLETE complete');
- this.complete();
- break;
- }
- },
- complete : function () {
- if (this.arrAnimation.length > 0) {
- if (this.arrAnimation.length == 1) {
- //如果是无限循环的
- if (this.arrAnimation[0].b == 0) {
- var arr = this.arrAnimation[0];
- this.arrAnimation.shift();
- this.addAnimation(arr);
- // cc.log(this.spine.animationName , ' 重复播放一个动作');
- }else{
- // cc.log(this.spine.animationName , ' 删除一个动作');
- this.arrAnimation.shift();
- return;
- }
- }else{
- this.arrAnimation.shift();
- this.delAnimation(this.arrAnimation[0]);
- return;
- }
- // cc.log(this.spine.animationName , ' 减少一个动作');
- // this.arrAnimation.shift();
- }
- if (null!=this.endListener) {
- this.endListener(this.spine.animationName);
- }
- },
- addAnimation : function (data) {
- this.arrAnimation.push(data);
- // cc.log(this.arrAnimation , ' 添加一个动作');
- if (this.arrAnimation.length == 1) {
- this.spine.playAnimation(data.name,1);
- }
- },
- delAnimation : function (data) {
- this.spine.playAnimation(data.name,1);
- },
- /**
- * @param name
- * @param b
- *
- // * -1 为使用配置文件中的次数。
- // * 0 为无限循环播放。
- // * >0 为动画的重复次数。
- */
- setAnimation : function (data) {
- this.arrAnimation = [];
- this.arrAnimation.push(data);
- this.spine.playAnimation(data.name,1);
- cc.log(this.arrAnimation , ' 设置一个动作');
- },
- initData: function () {
- //初始化 动作列表
- this.statusArr = [
- //0
- "FemaleRun",
- //1
- "FemaleAwait",
- // 2
- "FemaleRunFast",
- // 3
- "FemaleFall",
- // 4
- "FemaleJavRun",
- // 5
- "FemaleJavFast",
- // 6
- "FemaleJavFall",
- // 7
- "FemaleJavOut",
- // 8
- "FAnimalUp",
- // 9
- "FAnimalRun",
- // 10
- "FAnimalRunFast",
- // 11
- "FAnimalFall",
- // 12
- "FAnimalOut",
- // 13
- "FemaleJump",
- // 14
- "FemaleDown",
- // 15
- "FemaleSpan",
- // 16
- "FAnimalRunFast2",
- ];
- //todo 准备跑步动作
- this.statusArr_redyrun = [
- //0
- "FemaleAwait",
- ];
- this.arr = [];
- //todo 跑步动作
- this.statusArr_run = [
- //0
- "FemaleRun",
- //1
- "FemaleRunFast",
- //2
- "FemaleRunFast1",
- //3
- "FemaleRunFast2",
- //4
- "FemaleFall",
- ];
- this.arr.push(this.statusArr_run);
- //todo 跳远
- var a = [];
- this.statusArr_longjump = a.concat(this.statusArr_run);
- //5
- this.statusArr_longjump.push("FemaleJump");//这里应该是跳起落下的完整动画
- //6
- this.statusArr_longjump.push("FemaleDown");//这里应该是落下后再站起来的动画
- this.arr.push(this.statusArr_longjump);
- //todo 跨栏
- a = [];
- this.statusArr_hurdling = a.concat(this.statusArr_run);
- //5
- this.statusArr_hurdling.push("FemaleSpan");
- //6
- this.statusArr_hurdling.push("FemaleSpan");
- this.arr.push(this.statusArr_hurdling);
- //todo 蹬三轮
- this.statusArr_bike = [
- //0 跑1
- this.statusArr[9],
- //1 跑2
- this.statusArr[10],
- //2 跑3
- this.statusArr[16],
- //3 踉跄
- this.statusArr[11],
- //4 上车
- this.statusArr[8],
- //5 下车
- this.statusArr[12],
- ];
- this.arr.push(this.statusArr_bike);
- //todo 标枪项目
- this.statusArr_javelin = [
- //0 跑1
- this.statusArr[4],
- //1 跑2
- this.statusArr[4],
- //2 跑3
- this.statusArr[5],
- //3 踉跄
- this.statusArr[6],
- //4 捡标枪
- this.statusArr[7],
- //5 扔标枪
- this.statusArr[7],
- ];
- this.arr.push(this.statusArr_javelin);
- //todo 标枪
- this.statusArr_biaoqiang = [
- "Biaoqiang01",
- "Biaoqiang02",
- "Biaoqiang03",
- ];
- //初始化动作状态
- this.setStatus(this.statusArr[1]);
- this.setMyTag(null);
- },
- setMyTag: function (obj) {
- this.myTag = obj;
- },
- idle: function () {
- this.spine.timeScale = 1.0;
- // this.spine.setAnimation(0, this.statusArr_redyrun[0], true);
- var data = {
- name : this.statusArr_redyrun[0],
- b : 0
- }
- this.setAnimation(data);
- },
- idleadd: function () {
- var data = {
- name : this.statusArr_redyrun[0],
- b : 0
- }
- this.addAnimation(data);
- },
- idleadd1: function () {
- var data = {
- name : this.statusArr[5],
- b : 1
- }
- this.addAnimation(data);
- },
- idleadd2: function () {
- var data = {
- name : this.statusArr[6],
- b : 1
- }
- this.addAnimation(data);
- },
- addidle: function () {
- this.spine.setAnimation(0, this.statusArr_redyrun[0], false);
- },
- test: function () {
- this.spine.setAnimation(0, this.statusArr_run[2], true);
- },
- walk: function () {
- // .setAnimation(trackIndex,name,loop)设置当前动画。队列中的任何的动画将被清除。返回一个 sp.spine.TrackEntry 对象。
- var data = {
- name : this.statusArr[2],
- b : 1
- }
- this.addAnimation(data);
- },
- walkadd: function () {
- // .setAnimation(trackIndex,name,loop)设置当前动画。队列中的任何的动画将被清除。返回一个 sp.spine.TrackEntry 对象。
- var data = {
- name : this.statusArr[2],
- b : 0
- }
- this.addAnimation(data);
- },
- readyRun: function () {
- // this.spine.setAnimation(0, this.statusArr_redyrun[0], false);
- // this.spine.addAnimation(0, this.statusArr_redyrun[1], false);
- var data = {
- name : this.statusArr_run[0],
- b : 0
- }
- this.setAnimation(data);
- //奔跑等级
- this.walkLv = 0;
- },
- readyRun_add: function () {
- // this.spine.setAnimation(0, this.statusArr_redyrun[0], false);
- // this.spine.addAnimation(0, this.statusArr_redyrun[1], false);
- this.spine.addAnimation(0, this.statusArr_run[0], true);
- //奔跑等级
- this.walkLv = 0;
- },
- SetCurrentAnimationIdx: function (idx) {
- // this.spine.addAnimation(0, this.arr[this.type][idx], true);
- var data = {
- name : this.arr[this.type][idx],
- b : 0
- }
- this.addAnimation(data);
- },
- SetCurrentAnimationIdx_set: function (idx) {
- // this.spine.setAnimation(0, this.arr[this.type][idx], true);
- var data = {
- name : this.arr[this.type][idx],
- b : 0
- }
- this.setAnimation(data);
- },
- //todo 设置对应动作
- setCurrentSpeed: function () {
- this.walkLv = this.getSpeedLv();
- // cc.log("当前速度","档位",this.walkLv);
- // this.spine.addAnimation(0, this.arr[this.type][this.walkLv], true);
- var data = {
- name : this.arr[this.type][this.walkLv],
- b : 0
- }
- this.addAnimation(data);
- this.spine.timeScale = 1;
- },
- stagger: function () {
- // this.spine.setAnimation(0, this.arr[this.type][3], false);
- var data = {
- name : this.arr[this.type][3],
- b : 1
- }
- this.setAnimation(data);
- },
- longjump: function (jumpTimer) {
- cc.log('************longjump**********');
- // this.spine.timeScale = 1.5;
- // this.spine.setAnimation(0, this.statusArr_longjump[5], false);
- var data = {
- name: this.statusArr_longjump[5],
- b: 1
- };
- this.setAnimation(data);
- this.spine.timeScale = 1/jumpTimer;
- // console.log("timeScale ==", jumpTimer, this.spine.timeScale);
- var OutTimer = jumpTimer* 1000 + 300;
- // console.log("jumpTimer ==", jumpTimer, OutTimer);
- setTimeout(function () {
- cc.log('************longjump*****timeout*****');
- if (this.timeOutLongJumpListener != null) {
- this.timeOutLongJumpListener();
- }
- }.bind(this), OutTimer);
- },
- setTimeOutLongJumpListener: function (timeOutLongJumpListener) {
- this.timeOutLongJumpListener = timeOutLongJumpListener;
- },
- longjump_stagger: function () {
- this.spine.setAnimation(0, this.statusArr_longjump[1], false);
- this.setCurrentSpeed();
- },
- hurdling: function (callBack) {
- var data = {
- name : this.statusArr_hurdling[5],
- b : 0
- }
- this.setAnimation(data);
- // this.spine.setAnimation(0, this.statusArr_hurdling[5], false);
- // this.spine.addAnimation(0, this.statusArr_hurdling[this.walkLv], true);
- this.spine.timeScale = 1.5;
- // if (callBack != null) {
- // this.spine.setInterruptListener(function (trackEntry) {
- // var animationName = trackEntry.animation ? trackEntry.animation.name : "";
- // if ("hurdling_1" == animationName) {
- // callBack(animationName);
- // this.spine.timeScale = 1;
- // }
- // }.bind(this));
- //
- // }
- this.setEndListener(function (animationName) {
- if (animationName == this.statusArr_hurdling[5]) {
- if (callBack != null) {
- callBack(animationName);
- }
- this.spine.timeScale = 1;
- }
- }.bind(this));
- this.setCurrentSpeed();
- },
- hurdling_stagger: function () {
- this.spine.setAnimation(0, this.statusArr_hurdling[1], false);
- this.setCurrentSpeed();
- },
- //单纯的停止
- stop: function () {
- // .clearTrack(对应状态数字)清除出指定 track 的动画状态。
- this.spine.clearTrack(0);
- this.setStatus(this.statusArr_redyrun[0]);
- },
- //调用一次 暂停 再调用 恢复
- paused: function () {
- // .clearTrack(对应状态数字)清除出指定 track 的动画状态。
- if (this.spine.paused) {
- this.spine.paused = false;
- } else {
- this.spine.paused = true;
- }
- },
- /**
- * 设置当前的运动状态
- * @param status
- */
- setStatus: function (status) {
- this.myStatus = status;
- },
- //按屏幕了
- setOnTouchListener: function () {
- this.setType();
- // cc.log("当前游戏 按屏幕了", cc.find('Canvas').getComponent("GameStates").CurrentProgress);
- if (this.spine.animationName == this.statusArr_redyrun[0]) {
- // this.setCurrentSpeed();
- switch (this.type) {
- case 0:
- this.readyRun();
- break;
- case 3:
- this.BikeRun();
- break;
- }
- return;
- }
- },
- //todo 跨栏 跳跃
- setOnHurdlingListener: function (callBack) {
- this.setType();
- this.hurdling(callBack);
- },
- //todo 跨栏 踉跄
- setOnHurdlingStaggerListener: function () {
- this.setType();
- this.hurdling_stagger();
- },
- //todo 跳远跳跃
- setOnLongJumpListener: function (jumpTimer) {
- this.setType();
- this.longjump(jumpTimer);
- },
- //todo 跳远 踉跄
- setOnLongJumpStaggerListener: function () {
- this.setType();
- this.stagger();
- },
- //摔倒了
- setOnTripListener: function () {
- this.setType();
- this.stagger();
- },
- toggleTimeScale: function () {
- // .timeScale当前骨骼中所有动画的时间缩放率。
- if (this.spine.timeScale === 1.0) {
- this.spine.timeScale = 0.3;
- } else {
- this.spine.timeScale = 1.0;
- }
- },
- setEndListener: function (endListener) {
- this.endListener = endListener
- },
- endListener: function () {
- },
- setInterruptListener: function (interruptListener) {
- this.interruptListener = interruptListener
- },
- interruptListener: function () {
- },
- //todo 快上车 没时间解释了
- upBike: function () {
- this.setType();
- // this.spine.setAnimation(0, this.statusArr_bike[9], false);
- // this.spine.addAnimation(0, this.statusArr_bike[0], true);
- //
- var data = {
- name : this.statusArr_bike[4],
- b : 1
- }
- this.setAnimation(data);
- var dataadd = {
- name : this.statusArr_bike[0],
- b : 0
- }
- // cc.log('==============分割线============');
- cc.log(dataadd.name);
- this.addAnimation(dataadd);
- this.walkLv = 0;
- cc.find('Canvas').getComponent('GameStates').CurrentProgress = GameStatesStatic.GameProgress.RideBike;
- },
- BikeRun:function(){
- var dataadd = {
- name : this.statusArr_bike[0],
- b : 0
- }
- // cc.log('***************分割线*************');
- // cc.log(dataadd.name);
- this.setAnimation(dataadd);
- },
- //todo 快下车 没时间解释了
- downBike: function (callBack) {
- this.setType();
- // this.spine.setAnimation(0, this.statusArr_bike[4], false);
- var data = {
- name : this.statusArr_bike[5],
- b : 1
- }
- this.setAnimation(data);
- cc.log('设置了动画呀。');
- if (callBack != null) {
- // this.spine.setEndListener(function (trackEntry) {
- // var animationName = trackEntry.animation ? trackEntry.animation.name : "";
- // if (animationName == this.statusArr_bike[0]) {
- // callBack(animationName);
- // }
- // }.bind(this));
- this.setEndListener(function (animationName) {
- if (animationName == this.statusArr_bike[5]) {
- callBack(animationName);
- }
- }.bind(this));
- }
- this.walkLv = 0;
- },
- //todo 快拿标枪 没时间解释了
- upJavelin: function () {
- this.setType();
- // this.spine.setAnimation(0, this.statusArr_javelin[1], true);
- var data = {
- name : this.statusArr_javelin[0],
- b : 0
- }
- this.setAnimation(data);
- },
- //todo 快扔标枪 没时间解释了
- upJavelin_go: function (callBack) {
- this.setType();
- // this.spine.setAnimation(0, this.statusArr_javelin[6], false);
- var data = {
- name : this.statusArr_javelin[5],
- b : 1
- }
- this.setAnimation(data);
- this.spine.timeScale = 1;
- // setTimeout(function () {
- // this.spine.timeScale = 1;
- // }.bind(this), 600);
- // this.walkLv = 0;
- if (callBack != null) {
- this.spine.setEndListener(function (trackEntry) {
- var animationName = trackEntry.animation ? trackEntry.animation.name : "";
- callBack(animationName);
- }.bind(this));
- }
- },
- //todo 快扔标枪 没时间解释了
- javelin: function () {
- this.setType();
- this.spine.armatureName = 'Jav';
- this.spine.playAnimation('JavFly', -1);
- // cc.log('??????????????');
- this.spine.setAnimation(0, this.statusArr_biaoqiang[0], false);
- this.spine.addAnimation(0, this.statusArr_biaoqiang[1], false);
- this.spine.addAnimation(0, this.statusArr_biaoqiang[2], false);
- },
- setType: function () {
- // return;
- var temp = cc.find('Canvas').getComponent("GameStates").CurrentProgress;
- // cc.log("现在那标枪",temp);
- switch (temp) {
- case GameStatesStatic.GameProgress.Race:
- this.type = 0;
- // cc.log("当前的typssssse","s1");
- break;
- case GameStatesStatic.GameProgress.LongJump:
- this.type = 1;
- // cc.log("当前的typssssse","s2");
- break;
- case GameStatesStatic.GameProgress.Hurdle:
- this.type = 2;
- // cc.log("当前的typssssse","s3");
- break;
- case GameStatesStatic.GameProgress.RideBike:
- this.type = 3;
- // cc.log("当前的typssssse","s4");
- break;
- case GameStatesStatic.GameProgress.Javelin:
- this.type = 4;
- // cc.log("当前的typssssse","s5");
- break;
- }
- },
- getSpeedLv: function () {
- var TouchLayout = cc.find("TouchLayout");
- // var lv = TouchLayout.getComponent("NodeTouch").Hero.getComponent("HeroControl").PlayerStateScript.CurrentSpeed;
- var lv = cc.find('Hero').getComponent("HeroControl").PlayerStateScript.CurrentSpeed;
- var state = PlayerState.SpeedRangeForAnimation;
- if (lv >= state.SlowSpeed[0] && lv <= state.SlowSpeed[1]) {
- return 0;
- }
- if (lv >= state.MiddleSpeed[0] && lv <= state.MiddleSpeed[1]) {
- return 1;
- }
- if (lv >= state.HightSpeed[0] && lv <= state.HightSpeed[1]) {
- return 2;
- }
- return 0;
- }
- });
|