FCloseDoor.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import FF from "../FF";
  2. import FSprite from "../object/FSprite";
  3. /**
  4. * 触发机关关门
  5. */
  6. const {ccclass, property} = cc._decorator;
  7. @ccclass
  8. export default class FCloseDoor extends cc.Component {
  9. /**
  10. * 伙伴初始化区域
  11. */
  12. @property({
  13. type:cc.Node,
  14. displayName: '摄像机移动的目标位置'
  15. })
  16. mCameraPos: cc.Node = null;
  17. /**
  18. * 控制的栅栏
  19. */
  20. @property([cc.Node])
  21. mFenceTrigger: Array<cc.Node> = [];
  22. private ff:FF;
  23. onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider){
  24. if(otherCollider.node.group == 'A'){//主角踩到机关
  25. let obj = otherCollider.node.getComponent(FSprite);
  26. this.ff = obj.ff;
  27. if(obj == this.ff.mainSprite){
  28. this.node.removeComponent(cc.PhysicsBoxCollider);
  29. this.ff.pauseSprite(true)
  30. this.moveCamera(()=>{
  31. cc.tween(this).sequence(
  32. cc.delayTime(1),
  33. cc.callFunc(()=>{
  34. this.ff.pauseSprite(false)
  35. })
  36. ).start();
  37. for (let i = 0; i < this.mFenceTrigger.length; i++) {
  38. const element = this.mFenceTrigger[i];
  39. element.active = true;
  40. let nodes = element.children;
  41. nodes.forEach(tmp => {
  42. let spine = tmp.getComponent(sp.Skeleton);
  43. if(spine){
  44. spine.setAnimation(0, 'open', false);
  45. }
  46. });
  47. }
  48. })
  49. }
  50. }
  51. }
  52. private moveCamera(finishCallback:()=>void){
  53. if(!this.mCameraPos){
  54. finishCallback();
  55. return;
  56. }
  57. let map = this.ff.mMap;
  58. let camera = map.mCamera;
  59. let pos = cc.v2();
  60. let winsize = cc.winSize;
  61. pos.x = this.node.x + this.mCameraPos.x-winsize.width/2;
  62. pos.y = this.node.y + this.mCameraPos.y-winsize.height/2;
  63. cc.tween(camera.node).sequence(
  64. cc.moveTo(1,pos),
  65. cc.callFunc(()=>{
  66. finishCallback();
  67. })
  68. ).start()
  69. }
  70. }