Ok so my physics just doesnt want to work for one image!
heres the code to the lua file
local composer = require( "composer" ) local scene = composer.newScene() local \_W = display.contentWidth local \_H = display.contentHeight local physics = require("physics" ) physics.setScale( 30 ) physics.setGravity( 0, 0 ) physics.start( ) physics.setDrawMode( "hybrid" ) function scene:create( event ) local sceneGroup = self.view physics.start() ---------------------------- local BackGround = display.newImageRect("BackGround.png", 1080, 1920) sceneGroup:insert( BackGround ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then physics.start() elseif ( phase == "did" ) then physics.start() local circle = {} local dragCircle = function( event ) local target = event.target local phase = event.phase if ( event.phase == "began" ) then local parent = target.parent display.getCurrentStage():setFocus( target ) target.isFocus = true target.x0 = event.x - target.x target.y0 = event.y - target.y target.xStart = target.x target.yStart = target.y target:toFront() elseif ( target.isFocus ) then if ( phase == "moved" ) then target.x = event.x - target.x0 target.y = event.y - target.y0 elseif ( phase == "ended" or phase == "cancelled" ) then display.getCurrentStage():setFocus( nil ) target.isFocus = false transition.to( event.target, {time=500, x=event.target.xOrig, y=event.target.yOrig} ) end end return true end local spawnCircles = function () local FallDown = math.random(display.contentWidth \* 0.2, display.contentWidth \* 0.8 ) circle = display.newImageRect("circle.png", 31, 31 ) circle.x = FallDown circle.y = -70 physics.addBody( circle, "dynamic", {density = .01, friction = 0.5, bounce = 0.1 }) circle.gravityScale = 0.1 physics.setGravity( 0, 10 ) circle:addEventListener( "touch", dragCircle ) end myTimer = timer.performWithDelay( 2000, spawnCircles, -1) --1000 is the time end return true end -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene
and if i add
local floor = display.newImageRect("floor.png", 351, 32 ) floor.x = display.contentWidth \* 0.5 floor.y = 520 physics.addBody(floor, "static")
if i add the floor to create scene it starts to duplicate the circles falling down … and las out corona sdk
if i add it into the “will” part then is stops duplicating my circles and physics doesnt work
and if i put it into the “did” part its starts dulpicating the cirlces and lags out corona… but it does start physics…
please help my on this… and when physics doesnt work for that floor it gives me this error code in the console…
physics.addBody cannot be called when the world is locked and in the middle of number crunching such as during a collision event
if you guys would like me to make a youtube vid explaining all this i can in a little bit… ive been stuck for weeks and cant figure it out… thanks :( 