Graphics画扇形的实现方法

游戏中需要画扇形功能,纪录一下 == Graphics 画扇形 ==

代码

function test() {
		this.Graphics.clear();
		let r = 100 //半径
		let startRadians = -0.25*Math.PI; //起始角度
		let endRadian = 0.25*Math.PI;//结束角度
		let start = cc.v2(100, 100); //圆心点
        let point1 = cc.v2(Math.cos(startRadians)*r + start.x, Math.sin(startRadians)*r + start.y)
        let point2 = cc.v2(Math.cos(endRadian)*r + start.x, Math.sin(endRadian)*r + start.y)
        
		//画扇形的三角区域
        this.Graphics.moveTo(start.x, start.y);
        this.Graphics.lineTo(point1.x, point1.y);
        this.Graphics.lineTo(point2.x, point2.y);
        this.Graphics.lineTo(start.x, start.y); 
		
		//画扇形的圆弧区域
        this.Graphics.arc(start.x, start.y, r, startRadians, endRadian, true)
        this.Graphics.fill();
}

End

有其他更好的方法请留言,感谢

point2可以不用计算。

        this.Graphics.moveTo(start.x, start.y);
        this.Graphics.lineTo(point1.x, point1.y);
        this.Graphics.arc(start.x, start.y, r, startRadians, endRadian, true)
        this.Graphics.lineTo(start.x, start.y); 
        this.Graphics.fill();

或者用Sprite的filled模式来模拟。

:ok_hand:,thank