Simulator crash when using director class with physics

I am having trouble using the director class when using the physics API. I have made a small example below. As soon as I add the physics.addBody line the simulator will crash. The code below is loaded by a director:changeScene in another module that also loads the physics package.

What I am doing wrong here?

Thanks
Thomas

[code]
module(…, package.seeall)

local gameGroup

function new()
gameGroup = display.newGroup()
local background = display.newRect(0,0,display.contentWidth,display.contentHeight*2)
background:setFillColor(255,255,255)
gameGroup:insert(background)

local bottomEdge = display.newRect(0,display.contentHeight*2,display.contentWidth, 10)
bottomEdge:setFillColor(255,0,0)
physics.addBody(bottomEdge, { density = 1.0, friction = 0.3, bounce = 0.2 } )
gameGroup:insert(bottomEdge)

return gameGroup
end [import]uid: 21783 topic_id: 6140 reply_id: 306140[/import]

@benny101

The physics module will only work if you require it at main.lua file once or if you require it individually at all the files you want to use it. [import]uid: 8556 topic_id: 6140 reply_id: 21141[/import]

Hi Ricardo,

I have already included it in the main file. You can see the main file and the file that is called below. It is a really short example but enough to generate the problem. When I have the physics.addBody line there the simulator just crashes. If I delete the physics.addBody it runs ok and shows a white background.

Do you know what is going wrong?
Best,
Thomas

[code]
– main.lua
display.setStatusBar( display.HiddenStatusBar ) --Hide status bar from the beginning

– Import director class
local director = require(“director”)
local physics = require(“physics”)
local gameUI = require(“gameUI”)

– Create a main group
local mainGroup = display.newGroup()

– Main function
local function main()

– Add the group from director class
mainGroup:insert(director.directorView)

director:changeScene( “level3” )

return true
end

– Begin
main()

– level3.lua
module(…, package.seeall)

local gameGroup

function new()
gameGroup = display.newGroup()
local background = display.newRect(0,0,display.contentWidth,display.contentHeight*2)
background:setFillColor(255,255,255)
gameGroup:insert(background)

local bottomEdge = display.newRect(0,display.contentHeight*2,display.contentWidth, 10)
bottomEdge:setFillColor(255,0,0)
physics.addBody(bottomEdge, “static”)
gameGroup:insert(bottomEdge)

return gameGroup
end [import]uid: 21783 topic_id: 6140 reply_id: 21212[/import]

@benny101

You forgot to start the physics engine, please take a look at the link below to read some really useful information about it.

physics.start()  

http://developer.anscamobile.com/content/game-edition-box2d-physics-engine [import]uid: 8556 topic_id: 6140 reply_id: 21387[/import]

Ahh… thanks! That helped a bunch. Sorry, but I am completely new to this, but having great fun trying it out.

Thomas [import]uid: 21783 topic_id: 6140 reply_id: 21483[/import]

No problem, if you learned how to use it then it’s what matters! [import]uid: 8556 topic_id: 6140 reply_id: 21487[/import]