FFruit26.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import FF from "../../FF";
  2. import FSprite from "../../object/FSprite";
  3. import FDialogPack26 from "./FDialogPack26";
  4. /**
  5. * 摘果子任务中的果子
  6. */
  7. const {ccclass, property} = cc._decorator;
  8. @ccclass
  9. export default class FFruit26 extends cc.Component {
  10. @property({
  11. type:cc.ProgressBar,
  12. displayName: '进度条'
  13. })
  14. public mProgressBar:cc.ProgressBar = null;
  15. private ff:FF;
  16. public pick26:FDialogPack26;
  17. onLoad() {
  18. this.mProgressBar.node.active = false;
  19. }
  20. public setPick26(pick26:FDialogPack26){
  21. this.pick26 = pick26;
  22. }
  23. onBeginContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  24. if(other.node.group == 'A'){
  25. if(this.pick26 && this.pick26.state == 1){
  26. let obj = other.node.getComponent(FSprite);
  27. this.ff = obj.ff;
  28. if(obj == this.ff.mainSprite){
  29. this.showButton();
  30. }
  31. }
  32. }
  33. }
  34. onEndContact(contact: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider){
  35. if(other.node.group == 'A'){
  36. let obj = other.node.getComponent(FSprite);
  37. this.ff = obj.ff;
  38. if(obj == this.ff.mainSprite){
  39. this.closeButton();
  40. }
  41. }
  42. }
  43. public showButton(){
  44. this.ff.control.mEventButton.node.active = true;
  45. this.ff.control.mEventButton.setCallback(()=>{
  46. this.pick();
  47. });
  48. }
  49. public closeButton(){
  50. this.ff.control.mEventButton.node.active = false;
  51. }
  52. /**
  53. * 摘取果子
  54. */
  55. public pick(){
  56. this.mProgressBar.node.active = true;
  57. this.mProgressBar.progress = 0;
  58. this.ff.mBlockInputEvents.active = true;
  59. this.schedule(this.pupdate,0.1);
  60. }
  61. public pupdate(){
  62. let progress = this.mProgressBar.progress;
  63. progress += 0.1;
  64. this.mProgressBar.progress = progress;
  65. if(progress >= 1){
  66. this.ff.mBlockInputEvents.active = false;
  67. this.unschedule(this.pupdate);
  68. this.ff.mFFheader.addTmpGood(this.pick26.goodId,1);
  69. this.node.removeComponent(cc.PhysicsBoxCollider);
  70. cc.tween(this.node).sequence(
  71. cc.fadeOut(0.5),
  72. cc.destroySelf()
  73. ).start()
  74. }
  75. }
  76. }