GuideMask.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const { ccclass, property } = cc._decorator;
  2. /**
  3. * 引导的全局遮罩
  4. */
  5. @ccclass
  6. export default class GuideMask extends cc.Component {
  7. @property(cc.Node)
  8. mLayout0: cc.Node = null;
  9. @property(cc.Mask)
  10. mMask: cc.Mask = null;
  11. @property(cc.Node)
  12. mShadow: cc.Node = null;//背景阴影
  13. @property(cc.Node)
  14. guideMark: cc.Node = null;//引导提示标识
  15. /**
  16. * 当前目标对象
  17. */
  18. private pTargetNode: cc.Node = null;
  19. onLoad() {
  20. this.node.active = false;
  21. }
  22. public show() {
  23. this.node.active = true;
  24. this.mLayout0.on(cc.Node.EventType.TOUCH_START, (event) => {
  25. if (event.target == this.pTargetNode) {
  26. } else {
  27. event.stopPropagation();
  28. }
  29. }, true)
  30. this.mLayout0.on(cc.Node.EventType.TOUCH_MOVE, (event) => {
  31. if (event.target == this.pTargetNode) {
  32. } else {
  33. event.stopPropagation();
  34. }
  35. }, true)
  36. this.mLayout0.on(cc.Node.EventType.TOUCH_END, (event) => {
  37. if (event.target == this.pTargetNode) {
  38. } else {
  39. event.stopPropagation();
  40. }
  41. }, true)
  42. }
  43. public close() {
  44. this.node.active = false
  45. this.mLayout0.off(cc.Node.EventType.TOUCH_START);
  46. this.mLayout0.off(cc.Node.EventType.TOUCH_MOVE);
  47. this.mLayout0.off(cc.Node.EventType.TOUCH_END);
  48. }
  49. /**
  50. * 设置按钮
  51. * @param node
  52. */
  53. public setTargetNode(targetNode: cc.Node) {
  54. this.pTargetNode = targetNode;
  55. cc.tween(this).sequence(
  56. cc.delayTime(0.01),
  57. cc.callFunc(()=>{
  58. // cc.log('pos 1',targetNode.getPosition().x, targetNode.getPosition().y)
  59. let pos = this.pTargetNode.convertToWorldSpaceAR(cc.v2(0,0));
  60. // cc.log('pos 2',pos.x, pos.y)
  61. let width = cc.winSize.width
  62. let height = cc.winSize.height
  63. pos.x -= width / 2;
  64. pos.y -= height / 2;
  65. this.guideMark.x = pos.x;
  66. this.guideMark.y = pos.y;
  67. this.mMask.node.x = pos.x;
  68. this.mMask.node.y = pos.y;
  69. this.mMask.node.width = this.pTargetNode.width;
  70. this.mMask.node.height = this.pTargetNode.height;
  71. this.mShadow.x = -pos.x;
  72. this.mShadow.y = -pos.y;
  73. })
  74. ).start()
  75. }
  76. }