Of course. These are all lua files which are connected to the problem. In game_scene I’m calling game_manager function to start/stop the game. Which calls the physics.start/stop. I didn’t mean disabling joints. Sry, I meant to say I just didn’t create them to check if there anything wrong with the joints.
My console output says (if i check the game_manager function are called):
"game_manager.start()
game_manager.pause()
game_manager.start()"
game_scene.lua (managing scene related stuff) [lua]
function scene:show(event) local sceneGroup = self.view if(event.phase == "will") then elseif(event.phase == "did") then game\_manager.start() end end function scene.resume() timer.performWithDelay( 1, function() game\_manager.start() end) end function scene.finish(score, combo, life, \_resume) timer.performWithDelay( 1, function() game\_manager.pause() composer.showOverlay( "scripts.scenes.game\_menu\_overlay", { effect = "slideDown", time = 500, isModal = true, params={resume = \_resume}} ) end ) end
[/lua]
game_manager.lua (adding physics world, ui etc):[lua]
local function setupPhysics() physics.start(false) -- initiate --sleeping bodies disabled physics.setGravity( 0, 0 ) -- no gravity physics.setDrawMode( "normal" ) -- for debug hybrid else normal physics.setContinuous( true ) -- no tunneling physics.setPositionIterations( 8 ) -- default is 8 physics.setReportCollisionsInContentCoordinates( true ) -- cordiantes in pixels physics.setTimeStep(0) -- time based end local function setup(pipe\_number) setupHelpers() setupPhysics() -- ... -- setupUI() physics.pause() end function manager.start() physics.start() enemy\_manager.start() end function manager.pause() enemy\_manager.pause() physics.pause() end
[/lua]
anti_particle.lua(physics part):[lua]
physics.addBody(anti\_particle, "dynamic", {radius = 64-16,friction=0.0, density=1.0, bounce= 0.0, filter={categoryBits=8,maskBits=5}}) -- disable physical response anti\_particle.isSensor = true -- add rotation anti\_particle:setLinearVelocity( 0, speed) anti\_particle.angularVelocity = 30 --setup collision lsitener anti\_particle:addEventListener("collision", onCollision) --- shields setup shield\_manager = shield\_manager.create(anti\_particle, layer, speed) for i=1,#shields do shield\_manager:createShield(shields[i]) end
[/lua]
shield_manager.lua: ( just physics part)
physics.addBody(s, "dynamic", {radius = 64, friction=0.0, density=1.0, bounce = 0.0, filter={categoryBits=64,maskBits=0}}) s.isSensor = true s.angularVelocity = -30 -- create pivot joint local shield\_joint = physics.newJoint( "pivot", anti\_particle, s, anti\_particle.x, anti\_particle.y,s.x, s.y ) -- make motor to rotate shield shield\_joint.isMotorEnabled = true shield\_joint.motorSpeed = 100 shield\_joint.maxTorque = 10000 s:setLinearVelocity( 0, speed )
Thanks Dominik