draw.ts 923 B

123456789101112131415161718192021222324
  1. const {ccclass, property, executeInEditMode, playOnFocus} = cc._decorator;
  2. @ccclass
  3. @executeInEditMode
  4. export class Draw extends cc.Component {
  5. protected onLoad(): void {
  6. let debugDrawer = this.node.addComponent(cc.Graphics);
  7. debugDrawer.lineWidth = 5;
  8. debugDrawer.strokeColor = new cc.Color(255, 0, 0);
  9. debugDrawer.fillColor = new cc.Color(255, 0, 0);
  10. let size = this.node.getContentSize();
  11. if(size.width == 0){
  12. size = cc.size(10,10)
  13. }
  14. debugDrawer.moveTo(-size.width * 0.5 , -size.height * 0.5 );
  15. debugDrawer.lineTo(-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.stroke();
  20. }
  21. }