EffectLayer.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {CELL_WIDTH} from '../Model/ConstValue';
  2. import AudioUtils from "../Utils/AudioUtils";
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. // foo: {
  7. // default: null, // The default value will be used only when the component attaching
  8. // to a node for the first time
  9. // url: cc.Texture2D, // optional, default is typeof default
  10. // serializable: true, // optional, default is true
  11. // visible: true, // optional, default is true
  12. // displayName: 'Foo', // optional
  13. // readonly: false, // optional, default is false
  14. // },
  15. // ...
  16. bombWhite:{
  17. default: null,
  18. type: cc.Prefab
  19. },
  20. crushEffect:{
  21. default: null,
  22. type: cc.Prefab
  23. },
  24. audioUtils:{
  25. type: AudioUtils,
  26. default: null
  27. }
  28. },
  29. // use this for initialization
  30. onLoad: function () {
  31. },
  32. playEffects: function(effectQueue){
  33. if(!effectQueue || effectQueue.length <= 0){
  34. return ;
  35. }
  36. let soundMap = {}; //某一时刻,某一种声音是否播放过的标记,防止重复播放
  37. effectQueue.forEach(function(cmd){
  38. let delayTime = cc.delayTime(cmd.playTime);
  39. let callFunc = cc.callFunc(function(){
  40. let instantEffect = null;
  41. let animation = null;
  42. if(cmd.action == "crush"){
  43. instantEffect = cc.instantiate(this.crushEffect);
  44. animation = instantEffect.getComponent(cc.Animation);
  45. animation.play("effect");
  46. !soundMap["crush" + cmd.playTime] && this.audioUtils.playEliminate(cmd.step);
  47. soundMap["crush" + cmd.playTime] = true;
  48. }
  49. else if(cmd.action == "rowBomb"){
  50. instantEffect = cc.instantiate(this.bombWhite);
  51. animation = instantEffect.getComponent(cc.Animation);
  52. animation.play("effect_line");
  53. }
  54. else if(cmd.action == "colBomb"){
  55. instantEffect = cc.instantiate(this.bombWhite);
  56. animation = instantEffect.getComponent(cc.Animation);
  57. animation.play("effect_col");
  58. }
  59. instantEffect.x = CELL_WIDTH * (cmd.pos.x - 0.5);
  60. instantEffect.y = CELL_WIDTH * (cmd.pos.y - 0.5);
  61. instantEffect.parent = this.node;
  62. animation.on("finished",function(){
  63. instantEffect.destroy();
  64. },this);
  65. },this);
  66. this.node.runAction(cc.sequence(delayTime, callFunc));
  67. },this);
  68. },
  69. // called every frame, uncomment this function to activate update callback
  70. // update: function (dt) {
  71. // },
  72. });