spawnGroup.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. isFinishZone:false,
  5. isOnlyDelect: false,
  6. speed: 0,
  7. isSpawnOne:false,
  8. },
  9. start() {
  10. this.speed = -GlobalData.game.GameSpeed;//通过全局变量设置速度
  11. },
  12. update(dt) {
  13. if (GlobalData.game.state !== GlobalData.GameManager.State.Run) {
  14. return;
  15. }
  16. if (GlobalData.game.PlayerState == GlobalData.GameManager.PlayerState.Stop) {
  17. return;
  18. }
  19. this.speed = -GlobalData.game.GameSpeed;
  20. this.node.x += this.speed * dt;
  21. // console.log(this.node.getBoundingBoxToWorld().xMin);
  22. // if(this.node.getBoundingBoxToWorld().xMin <=0){
  23. // cc.director.pause();
  24. // }
  25. // var minValue = this.node.getBoundingBoxToWorld().xMin;
  26. // if(!this.isSpawnOne&&minValue<=0){
  27. // this.isSpawnOne = true;
  28. // GlobalData.spawnManager.spawnItem();
  29. // }
  30. if(this.isFinishZone&&this.node.getBoundingBoxToWorld().xMin<=350){
  31. //进入了减速区域
  32. GlobalData.game.isEnterGameFinishZone = true;
  33. }
  34. var disappear = this.node.getBoundingBoxToWorld().xMax < 0;
  35. if (disappear) {
  36. if(this.isFinishZone){
  37. //出了减速区域
  38. GlobalData.game.isEnterGameFinishZone = false;
  39. if(GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates == 'RideElephantRun'){
  40. GlobalData.game.getHeroControl().PlayerAnimControl.JumpOutElephant();
  41. GlobalData.game.getHeroControl().PlayerStatesScript.strPlayerStates = 'NormalRun';
  42. GlobalData.game.PlayerRunState = GlobalData.GameManager.PlayerRunState.NormalRun;
  43. cc.find('Canvas').getChildByName('PlayerShadow').scale = 1;
  44. }
  45. //重置属性
  46. GlobalData.gameMode.afterTheEndOfSports();
  47. }
  48. // console.log('清除');
  49. // this.node.destroy();
  50. if (this.isOnlyDelect) {
  51. //单纯的清除自己
  52. this.node.destroy();
  53. } else {
  54. //场景清除后接着生成,会影响场景生成
  55. GlobalData.spawnManager.despawnPipe(this);
  56. }
  57. }
  58. }
  59. });