Hello,
I’m working with anchor points on a project. Here is the sample code that represents the usage of anchor points. For some reason, when the transition begins, the earth’s physics body acts stationary.
1- The issue needs to be done with anchor points.
2- Also, I attached two png files that shows the transition pause/start stages.
[lua]local physics = require ( “physics” )
physics.start()
physics.setDrawMode(“hybrid”)
physics.setGravity(0.0, 0.0)
display.setDefault( “isAnchorClamped”, false )
– Initialize the variables
local width = display.contentWidth
local height = display.contentHeight
local startTimer
local startTimer2
local timerControl = false
local timerControl2 = false
– Initialize the objects and physics -> Sun, earth
local sun = display.newImageRect(“sun.png”, 200, 200)
sun:translate(width / 2, height / 2)
local earth = display.newImageRect(“earth.png”, 50, 50)
earth:translate(sun.x, sun.y)
earth.anchorX = 5
physics.addBody(sun, “static”, { radius = 45 })
physics.addBody(earth, “static”, { radius = 23 })
– Initialize the functions
function moveRight()
if (earth.anchorX > 3 and not timerControl) then
earth.anchorX = earth.anchorX - 0.1
else
timerControl = true
timerControl2 = true
end
end
function moveLeft()
if (earth.anchorX < 5 and timerControl2) then
earth.anchorX = earth.anchorX + 0.1
else
timerControl = false
timerControl2 = false
end
end
function initializeTimer()
startTimer = timer.performWithDelay(50, moveRight, -1)
startTimer2 = timer.performWithDelay(50, moveLeft, -1)
end
transition.to( earth, { iterations = -1, onStart = initializeTimer } )[/lua]