而是與setGravity
選項打轉轉,我想你應該只需旋轉使用像這樣的圖片:
local physics = require("physics")
physics.start()
physics.setGravity(0, 0)
display.setStatusBar(display.HiddenStatusBar)
local background = display.newImage("space.png", true)
background.x = display.contentWidth/2
background.y = display.contentHeight/2
local earth = display.newImage("earth.png")
earth.x = 100; earth.y = 200
earth.xScale = 0.7
earth.yScale = 0.7
physics.addBody(earth, {radius=40 })
earth.bodyType = "static"
local moon = display.newImage("moon.png", 40, 40)
moon.x = earth.x + 80
moon.y = earth.y
moon.xScale = 0.3
moon.yScale = 0.3
moon.rotation = 100
physics.addBody(moon, {radius=10 })
moon.bodyType = "dynamic"
myJoint = physics.newJoint("pivot", moon, earth, earth.x, earth.y)
local orbit = function(event)
moon.rotation = moon.rotation + 1.5
end
請注意,我不是真的擺弄setGravity
,但是旋轉的速度在orbit
函數中定義。
上面的代碼假定你只有圖像文件來表示你的行星體。如果是這樣,你將不得不使用上面的常量(earth.x
和earth.y
,縮放值等),以使整個系統LOOK適合您選擇的圖像。
祝你好運!