start physics without require "physics" if there is require "composer"

Hi,

It seems that we can start physics without requiring physics if we already require composer. The following code works:

local composer = require "composer" physics.start()

Is it a bug or something by design?

Thanks,

Lin

Hi Lin,

This doesn’t seem correct. Are you sure it’s actually starting the physics engine? Are you able to create physics objects after that and does it work as expected?

Brent

Interesting. I’m going to try it with an empty project folder and see what happens.

Is it possible that physics has already been required and declared as a global variable in another file?

Hi Brent and all,

I have only one file and you can try below:

local composer = require "composer" physics.start() local circle = display.newCircle(display.contentWidth/2, 50, 20) local line = display.newRect(display.contentWidth/2, display.contentHeight/2, display.contentWidth, 10) physics.addBody(circle) physics.addBody(line, "static")

No error at all, the circle just drop and hit the line. I’m using current public release (build 2014.2511). Removing “require composer” will generate error.

Regards,

Lin

physics has “always” (at least since i first began using Corona years ago) leaked a global “physics”. try this:

local not\_physics = require("physics") -- unusual reference name physics.start() -- tah dah!

or even simpler, this:

require("physics") -- no reference name at all physics.start() -- tah dah!

Hi Lin,

This doesn’t seem correct. Are you sure it’s actually starting the physics engine? Are you able to create physics objects after that and does it work as expected?

Brent

Interesting. I’m going to try it with an empty project folder and see what happens.

Is it possible that physics has already been required and declared as a global variable in another file?

Hi Brent and all,

I have only one file and you can try below:

local composer = require "composer" physics.start() local circle = display.newCircle(display.contentWidth/2, 50, 20) local line = display.newRect(display.contentWidth/2, display.contentHeight/2, display.contentWidth, 10) physics.addBody(circle) physics.addBody(line, "static")

No error at all, the circle just drop and hit the line. I’m using current public release (build 2014.2511). Removing “require composer” will generate error.

Regards,

Lin

physics has “always” (at least since i first began using Corona years ago) leaked a global “physics”. try this:

local not\_physics = require("physics") -- unusual reference name physics.start() -- tah dah!

or even simpler, this:

require("physics") -- no reference name at all physics.start() -- tah dah!