physics.setGravity

When I run my game on the simulator I have the gravity set as  physics.setGravity( 0,20)

When I try this on a nexus 7 the gravity behaves as on the simulator but when I try it on a kindle fire

the gravity does not behave the same and I need to set it to about  physics.setGravity( 0,26) to have a similar effect

I need it to work the same on all phones

Hi @nijelc,

How do you have your config.lua set up? Can you post it here?

Thanks,

Brent

local aspectRatio = display.pixelHeight / display.pixelWidth

application = {

  content = {
      graphicsCompatibility = 1,
      width = aspectRatio > 1.5 and 800 or math.ceil( 1200 / aspectRatio ),
      height = aspectRatio < 1.5 and 1200 or math.ceil( 800 * aspectRatio ),
      scale = “zoomStretch”,
      fps = 60,

      imageSuffix = {
         ["@2x"] = 1.3,
      },
   },

}

Hi @nijelc,

Chances are, by doing this calculation “trick” for the content width and height, you’re ending up with a completely different content size between the devices you’re testing on. When using physics, I don’t recommend this approach… the physics engine is based on the content size, so if you change it between devices, the physics will behave differently (i.e. a ball will take longer to fall down the distance on one screen than it will on another screen, because there are more pixels on the first compared to the second).

A better approach is to properly manage the content size, keep the same overall scale, and cleverly manage either the “empty bars” that may result in letterbox or the “bleed” that may result in “zoomEven”.

Hope this helps,

Brent

Thanks for you advice I will try that but I only notice the difference on the actual device if I use the simulator I dont notice any difference

Hi @nijelc,

You should notice the difference if you change the view (Window > View As) to Android devices similar to those you’re testing…

Hi

Yes I realise that but I find the difference barely noticible when I switch from nexus 7 to say galaxy s111 its only on the actual kindle that its markedly different. Can the framerate have anything to do with it I think the Kindle is slower. Do you think I need to set the gravity and apply force differently if the max framerate is 30 instead of 60. Can you work out the max framrate before the main loop begins.

Thanks

Hi @nijelc,

You may want to experiment with setting the physics “time step” instead of using frame-based (default). This is a fairly uncommon setting though, so I can’t vouch whether it will fix the issue you’re seeing. Here’s the documentation on it:

http://docs.coronalabs.com/api/library/physics/setTimeStep.html

Best regards,

Brent

Brilliant

setting physics.setTimeStep( 1/30 ) makes the kindle play exactly the same as the nexus

Thanks

Hi @nijelc,

How do you have your config.lua set up? Can you post it here?

Thanks,

Brent

local aspectRatio = display.pixelHeight / display.pixelWidth

application = {

  content = {
      graphicsCompatibility = 1,
      width = aspectRatio > 1.5 and 800 or math.ceil( 1200 / aspectRatio ),
      height = aspectRatio < 1.5 and 1200 or math.ceil( 800 * aspectRatio ),
      scale = “zoomStretch”,
      fps = 60,

      imageSuffix = {
         ["@2x"] = 1.3,
      },
   },

}

Hi @nijelc,

Chances are, by doing this calculation “trick” for the content width and height, you’re ending up with a completely different content size between the devices you’re testing on. When using physics, I don’t recommend this approach… the physics engine is based on the content size, so if you change it between devices, the physics will behave differently (i.e. a ball will take longer to fall down the distance on one screen than it will on another screen, because there are more pixels on the first compared to the second).

A better approach is to properly manage the content size, keep the same overall scale, and cleverly manage either the “empty bars” that may result in letterbox or the “bleed” that may result in “zoomEven”.

Hope this helps,

Brent

Thanks for you advice I will try that but I only notice the difference on the actual device if I use the simulator I dont notice any difference

Hi @nijelc,

You should notice the difference if you change the view (Window > View As) to Android devices similar to those you’re testing…

Hi

Yes I realise that but I find the difference barely noticible when I switch from nexus 7 to say galaxy s111 its only on the actual kindle that its markedly different. Can the framerate have anything to do with it I think the Kindle is slower. Do you think I need to set the gravity and apply force differently if the max framerate is 30 instead of 60. Can you work out the max framrate before the main loop begins.

Thanks

Hi @nijelc,

You may want to experiment with setting the physics “time step” instead of using frame-based (default). This is a fairly uncommon setting though, so I can’t vouch whether it will fix the issue you’re seeing. Here’s the documentation on it:

http://docs.coronalabs.com/api/library/physics/setTimeStep.html

Best regards,

Brent

Brilliant

setting physics.setTimeStep( 1/30 ) makes the kindle play exactly the same as the nexus

Thanks