Hello,
I read all forum article regards Shape and rotation without find a real solution. Then ....
I create my gideros class derived from Shape class. In fact, I want to create an real arc draw (acr + the two radius). My class is working but now I need to rotate my new draw. When I use myObject:setRotation(60) the image not rotate to the center point of my arc. Could someone help me to rotate my draw in the correct manner ?
Please find my code here :
------------------------------------------------------------------
Arc = gideros.class(Shape)
function Arc:init(t)
local x = t.x or t.y or 0
local y = t.y or t.x or 0
local fillStyle = t.fillStyle or { Shape.SOLID, 0x000000, 0.5 }
local lineStyle = t.lineStyle or { 2, 0xffffff, 0.5 }
local xradius = t.xradius or t.radius or 100
local yradius = t.yradius or t.radius or 100
local sides = t.sides or (xradius + yradius)/2
local arcAngle = t.arcAngle or 0
self:clear()
self:setFillStyle(unpack(fillStyle))
self:setLineStyle(unpack(lineStyle))
local angleStep = arcAngle / sides
self:beginPath()
self:moveTo(x, y)
for i = 1, arcAngle do
self:lineTo(x+math.cos(math.rad(i))*xradius, y+math.sin(math.rad(i))*yradius)
end
self:lineTo(x, y)
self:endPath()
if t.alpha then
self:setAlpha(t.alpha)
end
if t.parent then
t.parent:addChild(self)
end
return self
end
---------------------------------------------------------------------
Comments
I suppose you want to rotate the shape by its center.
Well the shape is rotated by it's 0,0 coordinate.
For example, if you draw rectangle like this:
But if you draw it like this:
Same way you should draw your arcs, by leaving 0,0 coordinate as the center of the circle
Also I think some drawing additions on Shape were here:
https://github.com/ar2rsawseen/GiderosCodingEasy/
You can take a peak
E.g. consider the built in graphics:
t=TextField.new(myfont,"my text")
t is now created as a textfield at (0,0). You can now position it
t:setPosition(100,200)
The creation command should only create the object. This is a good convention to follow.
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
thx ar2rsawseen and john26 . Build the arc at (0,0) and move it with setPosition solve my issue.
Now I can move the arc from the center of it !
Thanks for your help.
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975