Hello,
This is what I need and it does work this way most of the time.
But somethimes I get this while drawing
Not sure why.
This is the code.
let graphics, graphicNode: cc.Node;
this.node.on(cc.Node.EventType.TOUCH_START, (event) => {
graphicNode = new cc.Node();
this.graphicsDraw.addChild(graphicNode);
graphics = graphicNode.addComponent(cc.Graphics);
let g = graphics;
var nodePositionWrtWorld = this.node.parent.convertToWorldSpaceAR(event.getLocation());
var canvasNode = cc.find('Canvas');
this.lastPos = canvasNode.convertToNodeSpaceAR(nodePositionWrtWorld);
g.lineWidth = 5;
g.moveTo(this.lastPos.x, this.lastPos.y);
})
this.node.on(cc.Node.EventType.TOUCH_MOVE, (event: cc.Touch) => {
let g = graphics;
var nodePositionWrtWorld = this.node.parent.convertToWorldSpaceAR(event.getLocation());
var canvasNode = cc.find('Canvas');
g.lineTo(canvasNode.convertToNodeSpaceAR(nodePositionWrtWorld).x, canvasNode.convertToNodeSpaceAR(nodePositionWrtWorld).y);
g.stroke();
this.lastPos = canvasNode.convertToNodeSpaceAR(nodePositionWrtWorld);
});
this.node.on(cc.Node.EventType.TOUCH_END, (event: cc.Touch) => {
let g = graphics;
g.close()
g.stroke();
g.fillColor = new cc.Color(255, 0, 0, 255);
g.fill();
});
Can someone guide me?