Hello, can anybody give me some tutorial how to make arc object? There is nothing like that in docs, and i need this very badly.
What do you mean? Can you post a picture and explain a bit better? Thanks!
https://www.dropbox.com/s/tvkri44wlxp6uax/arc.jpg?dl=0
Something like that
Edit:
NVM i found this:
local function newArc(startAngle, widthAngle, radius ) startAngle = startAngle or 0 widthAngle = widthAngle or 90 radius = radius or 100 local vert = {} vert[#vert+1] = 0 vert[#vert+1] = 0 for i = 0, widthAngle do local a = (startAngle+i)\*math.pi/180 vert[#vert+1] = radius \* math.cos(a) vert[#vert+1] = radius \* math.sin(a) end local arc = display.newPolygon(0, 0, vert) arc:setFillColor(0,0,0) arc.strokeWidth = 1 arc:setStrokeColor( 0, 0, 0 ) return arc end local arc = newArc(0, 90, 50)
And you wanted it to be hollow in the middle??
Try this:
[lua]local function calcAnchorX( angles )
local result = 0
if (90 <= angles and angles < 270) then
result = 1
end
return result
end
local function calcAnchorY( angles )
local result = 1
if (180 <= angles) then
result = 0
end
return result
end
local function newSector(x, y, startAngle, widthAngle, radius, color )
startAngle = startAngle or 0
widthAngle = widthAngle or 90
radius = radius or 100
local vert = {}
vert[#vert+1] = 0
vert[#vert+1] = 0
for i = 0, widthAngle do
local a = -(startAngle+i)*math.pi/180
vert[#vert+1] = radius * math.cos(a)
vert[#vert+1] = radius * math.sin(a)
end
local arc = display.newPolygon(x, y, vert)
arc.anchorX = calcAnchorX(startAngle)
arc.anchorY = calcAnchorY(startAngle)
arc:setFillColor(color[1],color[2],color[3])
return arc
end
local function newArc(parent, x, y, startAngle, widthAngle, radius, color )
local startArea = math.floor( startAngle / 90 ) + 1
local finishArea = math.floor( (startAngle + widthAngle) / 90 ) + 1
local partCount = finishArea - startArea + 1
local sAngle = startAngle
local wAngle
if(finishArea > startArea) then
wAngle = (startArea * 90) - startAngle
else
wAngle = widthAngle
end
for i = 1, partCount do
if (i > 1) then
sAngle = (startArea - 1 + i - 1) * 90
if(i == partCount) then
wAngle = widthAngle + startAngle - sAngle
else
wAngle = 90
end
end
--print("ARC: ", sAngle, wAngle)
local arc = newSector(x, y, sAngle, wAngle, radius, color)
parent:insert(arc)
end
return parent
end
local strokeWidth = 3
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local radius = display.contentWidth / 2 - 50
local strokeWidth = 3
local strokeColor = {1,0,0}
local bgColor = {0,0,0}
local myGroup = display.newGroup()
– 1. image arc = (0 -> 30) + (110 -> 360) => widthAngle = 30 - 0 = 30 and widthAngle = 360 - 110 = 250
myGroup = newArc(myGroup, centerX, centerY, 0, 30, radius, strokeColor)
myGroup = newArc(myGroup, centerX, centerY, 110, 250, radius, strokeColor)
– 2. image arc = 180 -> 360 => widthAngle = 360 - 180 = 180
–myGroup = newArc(myGroup, centerX, centerY, 180, 180, radius, strokeColor)
– mask
local maskCircle = display.newCircle( myGroup, centerX, centerY, radius - strokeWidth )
maskCircle:setFillColor(bgColor)[/lua]
What do you mean? Can you post a picture and explain a bit better? Thanks!
https://www.dropbox.com/s/tvkri44wlxp6uax/arc.jpg?dl=0
Something like that
Edit:
NVM i found this:
local function newArc(startAngle, widthAngle, radius ) startAngle = startAngle or 0 widthAngle = widthAngle or 90 radius = radius or 100 local vert = {} vert[#vert+1] = 0 vert[#vert+1] = 0 for i = 0, widthAngle do local a = (startAngle+i)\*math.pi/180 vert[#vert+1] = radius \* math.cos(a) vert[#vert+1] = radius \* math.sin(a) end local arc = display.newPolygon(0, 0, vert) arc:setFillColor(0,0,0) arc.strokeWidth = 1 arc:setStrokeColor( 0, 0, 0 ) return arc end local arc = newArc(0, 90, 50)
And you wanted it to be hollow in the middle??
Try this:
[lua]local function calcAnchorX( angles )
local result = 0
if (90 <= angles and angles < 270) then
result = 1
end
return result
end
local function calcAnchorY( angles )
local result = 1
if (180 <= angles) then
result = 0
end
return result
end
local function newSector(x, y, startAngle, widthAngle, radius, color )
startAngle = startAngle or 0
widthAngle = widthAngle or 90
radius = radius or 100
local vert = {}
vert[#vert+1] = 0
vert[#vert+1] = 0
for i = 0, widthAngle do
local a = -(startAngle+i)*math.pi/180
vert[#vert+1] = radius * math.cos(a)
vert[#vert+1] = radius * math.sin(a)
end
local arc = display.newPolygon(x, y, vert)
arc.anchorX = calcAnchorX(startAngle)
arc.anchorY = calcAnchorY(startAngle)
arc:setFillColor(color[1],color[2],color[3])
return arc
end
local function newArc(parent, x, y, startAngle, widthAngle, radius, color )
local startArea = math.floor( startAngle / 90 ) + 1
local finishArea = math.floor( (startAngle + widthAngle) / 90 ) + 1
local partCount = finishArea - startArea + 1
local sAngle = startAngle
local wAngle
if(finishArea > startArea) then
wAngle = (startArea * 90) - startAngle
else
wAngle = widthAngle
end
for i = 1, partCount do
if (i > 1) then
sAngle = (startArea - 1 + i - 1) * 90
if(i == partCount) then
wAngle = widthAngle + startAngle - sAngle
else
wAngle = 90
end
end
--print("ARC: ", sAngle, wAngle)
local arc = newSector(x, y, sAngle, wAngle, radius, color)
parent:insert(arc)
end
return parent
end
local strokeWidth = 3
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local radius = display.contentWidth / 2 - 50
local strokeWidth = 3
local strokeColor = {1,0,0}
local bgColor = {0,0,0}
local myGroup = display.newGroup()
– 1. image arc = (0 -> 30) + (110 -> 360) => widthAngle = 30 - 0 = 30 and widthAngle = 360 - 110 = 250
myGroup = newArc(myGroup, centerX, centerY, 0, 30, radius, strokeColor)
myGroup = newArc(myGroup, centerX, centerY, 110, 250, radius, strokeColor)
– 2. image arc = 180 -> 360 => widthAngle = 360 - 180 = 180
–myGroup = newArc(myGroup, centerX, centerY, 180, 180, radius, strokeColor)
– mask
local maskCircle = display.newCircle( myGroup, centerX, centerY, radius - strokeWidth )
maskCircle:setFillColor(bgColor)[/lua]