creator 动态创建 cc.Graphics


creator 动态创建 cc.Graphics

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var newNode = new cc.Node();
this.new_draw_node = newNode.getComponent(cc.Graphics);
if (!this.new_draw_node) {
this.new_draw_node = this.node.addComponent(cc.Graphics);
}
this.node.addChild(newNode);

this.new_draw_node.clear(); // 清除以前的
// moveTo
this.new_draw_node.moveTo(-50, 50);
this.new_draw_node.lineTo(-50, -50);
this.new_draw_node.lineTo(50, -50);
this.new_draw_node.lineTo(50, 50);
this.new_draw_node.close(); // 组成一个封闭的路径
// end

// 画线,填充;
this.new_draw_node.stroke();
this.new_draw_node.fill();