About how to make star rotate by its middle point

Hi everyone 

Im newbie to here and for lua 

I got some problem hope u guys could help me

I open “lua sample code” “polylines”

so i can se 20 stars rotate in simulator

now I just want 1 star so I change 20 to 1

and it will rotate by white point in pic

but now I want it rotate by the red point,middle of star,

what should I do ?

I have no idea

pls help me or give me some hint

thx~~~

By default Corona SDK rotates around the center of the object.  Just change it’s .rotation value to what you want.    Are you using anchor points in any way?

Im not using anchor point cuz I have no idea where should I add it.
heres my code

display.setStatusBar( display.HiddenStatusBar ) -- Example of shape drawing function local function newStar() -- need initial segment to start local star = display.newLine( 0,0,0,-110, 27, -35) --local star = display.newLine( 0,-110, 27, -35) -- further segments can be added later star:append( 105,-35, 43,16, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, 0,-110) -- default color and width (can also be modified later) star:setStrokeColor( 255/255, 255/255, 25/2555, 255/255 ) star.strokeWidth = 3 return star end -- Create stars with random color and position local stars = {} \_W=display.contentWidth \_H=display.contentHeight for i = 1, 1 do local myStar = newStar() myStar.anchorX, myStar.anchorY= -1,-1 -- Graphics 2.0 needs colors from 0 to 1 myStar:setStrokeColor( math.random(255)/255, math.random(255)/255, math.random(255)/255, math.random(200)/255 + 55/255 ) myStar.strokeWidth = math.random(10) myStar.x = math.random( display.contentWidth) myStar.y = math.random( display.contentHeight) myStar.rotation = math.random(360) --myStar.rotation=myStar.rotation myStar.xScale = math.random(150)/105 myStar.yScale = myStar.xScale local point = display.newCircle(myStar.x, myStar.y, 5) --local point = display.newCircle(myStar.anchorX, myStar.anchorY, 5) local dr = math.random( 1, 4 ) myStar.dr = dr if ( math.random() \< 0.5 ) then myStar.dr = -dr end table.insert( stars, myStar ) end function stars:enterFrame( event ) for i,v in ipairs( self ) do v.rotation = v.rotation+ v.dr end end Runtime:addEventListener( "enterFrame", stars )

u can try this
i can make the star rotate in its middle point but their still a line connect its angle and middle point
what should i do ?
anyway thx RobMiracle

Try to use display.newPolygon() instead of display.newLine()'s. 

Rob

can u explain more for me?

I have no idea how to change my code to the right one~

Thx Rob I did it!!!

local halfW = display.contentWidth \* 0.5 local halfH = display.contentHeight \* 0.5 local vertices = { 0,-110, 27,-35, 105,-35, 43,16, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, } local o = display.newPolygon( halfW, halfH, vertices ) o.fill = { type="image", filename="mountains.png" } o.strokeWidth = 10 o:setStrokeColor( 1, 0, 0 ) o.rotation = math.random(360) local dr = math.random( 1, 4 ) o.dr = dr if ( math.random() \< 0.5 ) then o.dr = -dr end table.insert( o, o ) --table.insert( stars, myStar ) function o:enterFrame( event ) for i,v in ipairs( self ) do v.rotation = v.rotation+ v.dr end end Runtime:addEventListener( "enterFrame", o )

By default Corona SDK rotates around the center of the object.  Just change it’s .rotation value to what you want.    Are you using anchor points in any way?

Im not using anchor point cuz I have no idea where should I add it.
heres my code

display.setStatusBar( display.HiddenStatusBar ) -- Example of shape drawing function local function newStar() -- need initial segment to start local star = display.newLine( 0,0,0,-110, 27, -35) --local star = display.newLine( 0,-110, 27, -35) -- further segments can be added later star:append( 105,-35, 43,16, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, 0,-110) -- default color and width (can also be modified later) star:setStrokeColor( 255/255, 255/255, 25/2555, 255/255 ) star.strokeWidth = 3 return star end -- Create stars with random color and position local stars = {} \_W=display.contentWidth \_H=display.contentHeight for i = 1, 1 do local myStar = newStar() myStar.anchorX, myStar.anchorY= -1,-1 -- Graphics 2.0 needs colors from 0 to 1 myStar:setStrokeColor( math.random(255)/255, math.random(255)/255, math.random(255)/255, math.random(200)/255 + 55/255 ) myStar.strokeWidth = math.random(10) myStar.x = math.random( display.contentWidth) myStar.y = math.random( display.contentHeight) myStar.rotation = math.random(360) --myStar.rotation=myStar.rotation myStar.xScale = math.random(150)/105 myStar.yScale = myStar.xScale local point = display.newCircle(myStar.x, myStar.y, 5) --local point = display.newCircle(myStar.anchorX, myStar.anchorY, 5) local dr = math.random( 1, 4 ) myStar.dr = dr if ( math.random() \< 0.5 ) then myStar.dr = -dr end table.insert( stars, myStar ) end function stars:enterFrame( event ) for i,v in ipairs( self ) do v.rotation = v.rotation+ v.dr end end Runtime:addEventListener( "enterFrame", stars )

u can try this
i can make the star rotate in its middle point but their still a line connect its angle and middle point
what should i do ?
anyway thx RobMiracle

Try to use display.newPolygon() instead of display.newLine()'s. 

Rob

can u explain more for me?

I have no idea how to change my code to the right one~

Thx Rob I did it!!!

local halfW = display.contentWidth \* 0.5 local halfH = display.contentHeight \* 0.5 local vertices = { 0,-110, 27,-35, 105,-35, 43,16, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, } local o = display.newPolygon( halfW, halfH, vertices ) o.fill = { type="image", filename="mountains.png" } o.strokeWidth = 10 o:setStrokeColor( 1, 0, 0 ) o.rotation = math.random(360) local dr = math.random( 1, 4 ) o.dr = dr if ( math.random() \< 0.5 ) then o.dr = -dr end table.insert( o, o ) --table.insert( stars, myStar ) function o:enterFrame( event ) for i,v in ipairs( self ) do v.rotation = v.rotation+ v.dr end end Runtime:addEventListener( "enterFrame", o )