From 867723ebe60a4bc0ecdb6c99f2bb3bad67f1b4cb Mon Sep 17 00:00:00 2001 From: u0u0 Date: Sat, 17 Jul 2021 17:56:37 +0800 Subject: [PATCH] add newSector --- templates/src/framework/display.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/templates/src/framework/display.lua b/templates/src/framework/display.lua index 4d533b6..7e2453a 100644 --- a/templates/src/framework/display.lua +++ b/templates/src/framework/display.lua @@ -675,6 +675,32 @@ function display.newCircle(radius, params) return circle end +--[[ +local sector = display.newSector(50, 45, { + segments = 10, + scale = 1, + borderWidth = 1, + fillColor = cc.c4f(0.0, 1.0, 0.0, 1.0), + borderColor = cc.c4f(1.0, 0.0, 0.0, 1.0), +}) +]]-- +function display.newSector(radius, angle, params) + local segments = params.segments or 10 + local points = {} + local alpha = angle / (segments - 1) + local start = - angle / 2 + + table.insert(points, {0, 0}) -- center + for i = 0, segments - 1 do + local rad = math.rad(start + alpha * i) + local x = radius * math.cos(rad) + local y = radius * math.sin(rad) + table.insert(points, {x, y}) + end + + return display.newPolygon(points, params) +end + --[[ Create a rect DrawNode @function newRect