Here is my code, and my problem is
When my bullet spawn, it trigger the movebullet function.
All bullets transition.to the mainCircle. However, I have my mainRect, with physics, keep rotating and tried to avoid the bullet collide with the mainCircle. But when the transition is finished, the bullet will bounce all over the simulator
I think my problem is, when i have my transition.to working, the physics engine will not be detected?
And I can’t think of other thing to replace transition.to my mainCircle.
[lua]display.setStatusBar(display.HiddenStatusBar)
local physics = require “physics”
physics.start()
physics.setGravity ( 0, 0 )
local w = display.contentWidth
local h = display.contentHeight
local cx = display.contentCenterX
local cy = display.contentCenterY
local bulletGroup = display.newGroup ()
bulletGroup.anchorChildren = true
local mainCircle = display.newCircle ( 10, 10, 20 )
mainCircle.x = w * 0.5
mainCircle.y = h * 0.5
local mainRect = display.newRect ( mainCircle.x, mainCircle.y, 15, 130 )
mainRect:setFillColor ( 0.45, 0.1, 1 )
physics.addBody (mainRect, “static”, {bounce = 50.1})
function movebullet ()
transition.to ( bullet, {time = 5001, x = mainCircle.x, y = mainCircle.y } )
end
function rotate (event)
mainRect.rotation = mainRect.rotation + 3
end
timer.performWithDelay ( 300, rotate, -1 )
function addbullets ()
rand = math.random (4)
if (rand < 2 ) then
bullet = display.newCircle ( 0, 0, 5 )
bullet.x = math.random (w * -0.11, w * -0.1); bullet.y = math.random (h * 0, h * 1);
physics.addBody (bullet, “dynamic”, {bounce = 50.1})
bulletGroup:insert (bullet)
else if ( rand < 3 ) then
bullet = display.newCircle ( 0, 0, 5 )
bullet.x = math.random (w * 1.1, w * 1.11); bullet.y = math.random (h * 0, h * 1);
physics.addBody (bullet, “dynamic”, {bounce = 10.1})
bulletGroup:insert (bullet)
else if ( rand < 4 ) then
bullet = display.newCircle ( 0, 0, 5 )
bullet.x = math.random (w * 0, w * 1); bullet.y = math.random (h * -0.15, h * -0.14);
physics.addBody (bullet, “dynamic”, {bounce = 20.1})
bulletGroup:insert (bullet)
else if ( rand < 5 ) then
bullet = display.newCircle ( 0, 0, 5 )
bullet.x = math.random (w * 0, w * 1); bullet.y = math.random (h * 1.15, h * 1.16);
physics.addBody (bullet, “dynamic”, {bounce = 30.1})
bulletGroup:insert (bullet)
end
end
end
end
movebullet()
end
–Runtime:addEventListener (“touch”, addbullets)
timer.performWithDelay ( 500, addbullets, -1 )
[/lua]
Thanks Alot