playercontrols.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. },
  29. // LIFE-CYCLE CALLBACKS:
  30. // onLoad () {},
  31. start () {
  32. player = this
  33. this.An = this.node.getComponent(cc.Animation)
  34. this.Animations = utils.getAnimations(this.An);
  35. Log.info("所有表演",this.Animations)
  36. },
  37. leftok(b){
  38. // Log.info("打到了",b)
  39. if (this.LeftokListener) {
  40. this.LeftokListener();
  41. }
  42. },
  43. rightok(b){
  44. // Log.info("打到了",b)
  45. if (this.RightokListener) {
  46. this.RightokListener();
  47. }
  48. },
  49. //左侧击打监听
  50. setLeftokListener(LeftokListener){
  51. this.LeftokListener = LeftokListener;
  52. },
  53. setRightokListener(RightokListener){
  54. this.RightokListener = RightokListener;
  55. },
  56. // initListener(){
  57. // utils.setAnimationCallBack(this.An,"finished",,function () {
  58. // Log.info("现在回来的是什么")
  59. // }.bind(this));
  60. // },
  61. playLeft(){
  62. this.nowPlaying(function () {
  63. utils.startAnimation(this.An,this.Animations[1].name);
  64. // this.initListener();
  65. utils.setAnimationCallBack(this.An,"finished",this.Animations[1].name,function () {
  66. // Log.info("现在回来的是什么",this.Animations[1].name)
  67. this.setAn_normal();
  68. }.bind(this));
  69. }.bind(this));
  70. },
  71. playRight(){
  72. this.nowPlaying(function () {
  73. utils.startAnimation(this.An,this.Animations[2].name);
  74. utils.setAnimationCallBack(this.An,"finished",this.Animations[2].name,function () {
  75. // Log.info("现在回来的是什么",this.Animations[2].name)
  76. this.setAn_normal();
  77. }.bind(this));
  78. }.bind(this));
  79. },
  80. playMid(){
  81. this.nowPlaying(function () {
  82. utils.startAnimation(this.An,this.Animations[3].name);
  83. utils.setAnimationCallBack(this.An,"finished",this.Animations[3].name,function () {
  84. // Log.info("现在回来的是什么",this.Animations[3].name)
  85. this.setAn_normal();
  86. }.bind(this));
  87. }.bind(this));
  88. },
  89. playLeftBad(){
  90. this.nowPlaying(function () {
  91. utils.startAnimation(this.An,this.Animations[4].name);
  92. utils.setAnimationCallBack(this.An,"finished",this.Animations[4].name,function () {
  93. // Log.info("现在回来的是什么",this.Animations[3].name)
  94. this.setAn_normal();
  95. }.bind(this));
  96. }.bind(this));
  97. },
  98. playRightBad(){
  99. this.nowPlaying(function () {
  100. utils.startAnimation(this.An,this.Animations[5].name);
  101. utils.setAnimationCallBack(this.An,"finished",this.Animations[5].name,function () {
  102. // Log.info("现在回来的是什么",this.Animations[3].name)
  103. this.setAn_normal();
  104. }.bind(this));
  105. }.bind(this));
  106. },
  107. setAn_normal(){
  108. utils.startAnimation(this.An,this.Animations[0].name);
  109. },
  110. //动画播放中
  111. nowPlaying(callback){
  112. // Log.info("当前播放的是",this.An.currentClip ,this.Animations[0].name)
  113. if (this.An.currentClip == null || this.An.currentClip.name ==this.Animations[0].name ) {
  114. if (callback) {
  115. callback();
  116. }
  117. }
  118. }
  119. // update (dt) {},
  120. });