draw.ts 981 B

1234567891011121314151617181920212223242526
  1. import { Utils } from "../../Script/game/common/utils";
  2. const {ccclass, property, executeInEditMode, playOnFocus} = cc._decorator;
  3. @ccclass
  4. @executeInEditMode
  5. export class Draw extends cc.Component {
  6. protected start(): void {
  7. let debugDrawer = Utils.getCpt(cc.Graphics, this.node)
  8. debugDrawer.lineWidth = 5;
  9. debugDrawer.strokeColor = new cc.Color(255, 0, 0);
  10. debugDrawer.fillColor = new cc.Color(255, 0, 0);
  11. let size = this.node.getContentSize();
  12. if(size.width == 0){
  13. size = cc.size(10,10)
  14. }
  15. debugDrawer.moveTo(-size.width * 0.5 , -size.height * 0.5 );
  16. debugDrawer.lineTo(-size.width * 0.5 , +size.height * 0.5 );
  17. debugDrawer.lineTo(size.width * 0.5 , +size.height * 0.5 );
  18. debugDrawer.lineTo(size.width * 0.5 , -size.height * 0.5 );
  19. debugDrawer.lineTo(-size.width * 0.5 , -size.height * 0.5 );
  20. debugDrawer.stroke();
  21. }
  22. }