I have code for four circle object to move left and right constantly this way:
[code] local function batter()
local circle1 = display.newCircle(150,130,7)
circle1.strokeWidth = 1
circle1:setFillColor(0,225,0)
circle1:setStrokeColor(0,0,0)
physics.addBody(circle1, { density = 0, friction = 0, bounce = 0, })
local circle2 = display.newCircle(330,150,7)
circle2.strokeWidth = 1
circle2:setFillColor(0,225,0)
circle2:setStrokeColor(0,0,0)
physics.addBody(circle2, { density = 0, friction = 0, bounce = 0, })
local circle3 = display.newCircle(150,170,7)
circle3.strokeWidth = 1
circle3:setFillColor(0,225,0)
circle3:setStrokeColor(0,0,0)
physics.addBody(circle3, { density = 0, friction = 0, bounce = 0, })
local circle4 = display.newCircle(330,190,7)
circle4.strokeWidth = 1
circle4:setFillColor(0,225,0)
circle4:setStrokeColor(0,0,0)
physics.addBody(circle4, { density = 0, friction = 0, bounce = 0, })
local move_timer = nil
local trans = nil
local function move_one()
print(“move_one”)
local function move_two()
print(“move_two”)
trans = transition.to(circle1, {time=1200, x=150, y=130, onComplete=move_one})
end
trans = transition.to(circle1, {time=1200, x=330, y=130, onComplete=move_two})
end
move_one()
end
batter() ]]
local function batter1()
local circle2 = display.newCircle(330,150,7)
circle2.strokeWidth = 1
circle2:setFillColor(0,225,0)
circle2:setStrokeColor(0,0,0)
physics.addBody(circle2, { density = 0, friction = 0, bounce = 0, })
local move_timer1 = nil
local trans1 = nil
local function move_one1()
print(“move_one”)
local function move_two1()
print(“move_two”)
trans1 = transition.to(circle2, {time=1200, x=330, y=150, onComplete=move_one1})
end
trans1 = transition.to(circle2, {time=1200, x=150, y=150, onComplete=move_two1})
end
move_one1()
end
batter1()
local function batter2()
local circle3 = display.newCircle(150,170,7)
circle3.strokeWidth = 1
circle3:setFillColor(0,225,0)
circle3:setStrokeColor(0,0,0)
physics.addBody(circle3, { density = 0, friction = 0, bounce = 0, })
local move_timer2 = nil
local trans2 = nil
local function move_one2()
print(“move_one”)
local function move_two2()
print(“move_two”)
trans2 = transition.to(circle3, {time=1200, x=150, y=170, onComplete=move_one2})
end
trans2 = transition.to(circle3, {time=1200, x=330, y=170, onComplete=move_two2})
end
move_one2()
end
batter2()
local function batter3()
local circle4 = display.newCircle(330,190,7)
circle4.strokeWidth = 1
circle4:setFillColor(0,225,0)
circle4:setStrokeColor(0,0,0)
physics.addBody(circle4, { density = 0, friction = 0, bounce = 0, })
local move_timer3 = nil
local trans3 = nil
local function move_one3()
print(“move_one”)
local function move_two3()
print(“move_two”)
trans3 = transition.to(circle4, {time=1200, x=330, y=190, onComplete=move_one3})
end
trans3 = transition.to(circle4, {time=1200, x=150, y=190, onComplete=move_two3})
end
move_one3()
end
batter3()
[/code]
I wanted frist and third circle to move at the same speed and pattern.
and same for second and fourth.
At first it seemed like it works. But few minutes later, the circles odd move started to be noticeable.
I thought it’s because either the codes are unclear or too long.
so I deiced to make 4 different lua files for each circles, and call it at the same time.
Here’s circle1.lua file:
module(..., package.seeall)
local function batter()
local circle1 = display.newCircle(150,130,7)
circle1.strokeWidth = 1
circle1:setFillColor(0,225,0)
circle1:setStrokeColor(0,0,0)
physics.addBody(circle1, { density = 0, friction = 0, bounce = 0, })
local move\_timer = nil
local trans = nil
local function move\_one()
print("move\_one")
local function move\_two()
print("move\_two")
trans = transition.to(circle1, {time=1200, x=150, y=130, onComplete=move\_one})
end
trans = transition.to(circle1, {time=1200, x=330, y=130, onComplete=move\_two})
end
move\_one()
end
batter()
and I called it in a main.lua file like this:
local external = require("Circle1")
Circle1.batter()
but it’s not working.
Please help me! [import]uid: 131469 topic_id: 23183 reply_id: 323183[/import]
[import]uid: 52491 topic_id: 23183 reply_id: 92701[/import]

