Hi,
I’m a beginner. I have a problem. I want to make a star, and this star will rotate by its middle point (a blue circle).
In addition, I want the position and scale of this star will change randomly when I relaunch.
Now I have written a code that the star can rotate in a fixed position.
Please help me and give me some hints.
Thank you very much.
This is my code:
local physics = require ("physics") physics.start() x1, y1, x2, y2 = 200, 90, 305, 165 local star = display.newLine( x1,y1, 227,165) star:append( x2,y2, 243,216, 265,290, 200,245, 135,290, 157,215, 95,165, 173,165, 200,90 ) star:setStrokeColor( 1, 0, 0, 1 ) star.strokeWidth = 3 star.y = 0 physics.addBody(star,"dynamic") star.rotation = 0 function getDistance() dis = ((x2-x1)^2 + (y2-y1)^2)^0.5 dis = dis/2 pp = dis\*(-1+(5^0.5))/(5-2\*(5^0.5))^0.5 return pp end local pointY = getDistance() local sdot = display.newCircle(0, 0, 10 ) sdot:setFillColor( 0, 0, 1, 1 ) sdot.x = x1 sdot.y = pointY physics.addBody(sdot,"static", {isSensor=true}) local starJoint = physics.newJoint( "pivot", sdot, star, sdot.x, sdot.y ) starJoint.isMotorEnabled = true starJoint.motorSpeed = 40 starJoint.maxMotorTorque = 1000