CardMgr.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { _decorator, Component, Node, Sprite, UITransform, Vec2, Vec3, view } from 'cc';
  2. import { ModulerBase } from './ModulerBase';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('CardMgr')
  5. export class CardMgr extends ModulerBase {
  6. private _cards: Sprite[] = [];
  7. init(): void {
  8. this._cards = this.getComponentsInChildren(Sprite);
  9. }
  10. start() {
  11. }
  12. update(deltaTime: number) {
  13. }
  14. touchCard(pos: Vec2):boolean{
  15. for(const sprite of this._cards){
  16. const box = sprite.getComponent(UITransform).getBoundingBoxToWorld();
  17. if(box.contains(pos)){
  18. this.hide();
  19. return true;
  20. }
  21. }
  22. return false;
  23. }
  24. show(pos: Vec3): boolean{
  25. //view.getVisibleSize().width;
  26. //view.getVisibleSize().height;
  27. if(this.node.active){
  28. this.hide();
  29. return true;
  30. }
  31. this.node.setPosition(pos);
  32. this.node.active = true;
  33. return false;
  34. }
  35. hide(){
  36. this.node.active = false;
  37. }
  38. }