votes.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { _decorator, Color, Component, Graphics, Node } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('NewComponent')
  4. export class NewComponent extends Component {
  5. @property
  6. width: number = 400; // 初始宽度
  7. @property
  8. height: number = 500; // 高度
  9. @property
  10. cornerRadius: number = 100; // 圆角半径
  11. graphics: Graphics = null;
  12. start() {
  13. this.graphics = this.node.getComponent(Graphics);
  14. // const g = this.getComponent(Graphics);
  15. // g.lineWidth = 10;
  16. // g.fillColor.fromHEX('#ff0000');
  17. // g.moveTo(-40, 0);
  18. // g.lineTo(0, -80);
  19. // g.lineTo(40, 0);
  20. // g.lineTo(0, 80);
  21. // g.close();
  22. // g.stroke();
  23. // g.fill();
  24. this.graphics.clear();
  25. const h = this.height;
  26. const r = this.cornerRadius;
  27. // // 绘制渐变色
  28. // this.graphics.fillGradientRect(-width/2, -h/2, width, h, gradient);
  29. // 绘制圆角矩形
  30. this.graphics.fillColor.fromHEX('#ff0000');
  31. console.log('hhhhhhhhhhhhhhh'+h)
  32. this.graphics.roundRect(-this.width/2, -h/2, this.width, h, r);
  33. this.graphics.stroke();
  34. this.graphics.fill();
  35. }
  36. // drawRoundedRect() {
  37. // const h = this.height;
  38. // const r = this.cornerRadius;
  39. // this.graphics.clear();
  40. // // // 绘制渐变色
  41. // // const gradient = new GraphicsGradient([Color.WHITE, Color.BLACK], [0, 1]);
  42. // // this.graphics.fillGradientRect(-width/2, -h/2, width, h, gradient);
  43. // // 绘制圆角矩形
  44. // this.graphics.fillColor.fromHEX('#ff0000');
  45. // this.graphics.roundRect(-width/2, -h/2, width, h, r);
  46. // this.graphics.stroke();
  47. // this.graphics.fill();
  48. // }
  49. // // 使用此函数设置矩形宽度
  50. // setRectWidth(value) {
  51. // this.drawRoundedRect(value);
  52. // }
  53. update(deltaTime: number) {
  54. }
  55. }