Is it possible to draw a square and see it through the editor?
I don’t understand how to create a square using the graphics component through the editor? I added a graphics component to the empty node line width = 20 did, line cap = square did miter limit = 20 did. fill color = DF0000 but I see a square in the editor
Yes. It’s a very low-level drawing tool. Use it with editor only limits its capabilities. But if you really need you can encapsulating a component to use it in editor. Like this
import { _decorator, CCFloat, Component, Graphics, Node } from 'cc';
const { ccclass, property , executeInEditMode, requireComponent} = _decorator;
@ccclass('GraphicsTest')
@executeInEditMode
@requireComponent(Graphics)
export class GraphicsTest extends Component {
@property(CCFloat)
private _radis: number = 20;
@property(CCFloat)
public get radius(){
return this._radis;
}
public set radius(r: number){
this._radis = r;
this.draw();
}
draw(){
let g = this.getComponent(Graphics);
g.clear();
g.circle(0, 0, this._radis);
g.stroke();
}
start() {
this.draw();
}
}