Ground not keeping consistent size for different simulators

I have the ground in my game lifted about 30 pixles from the bottom of the screen, with a the player on top of it. This woks fine on the original simulator, but not on any of the other ones. Sometimes the ground is takes up over half the screen? I have not clue how tot fix this. 

My code:

[lua]

local ground2 = display.newImage(“game_ground.png”)

ground2.y = display.contentHeight

ground2.x = ground2.x -5

physics.addBody(ground2, “static”, { } )

group:insert(ground2)

player = display.newImage(“game_player.png”)

player.x = display.contentWidth - 25

player.y = ground.y - 60

player:scale(.7,.7)

physics.addBody(player, “static”, { radius = 10 } )

player.collision = playerCollision

player:addEventListener(“collision”, player)

group:insert(player)

[/lua]

and here is my config.lua if it matters:

[lua]

local aspectRatio = display.pixelHeight / display.pixelWidth

application =

{

content =

{

graphicsCompatibility = 1,  – Enable V1 Compatibility mode

width = aspectRatio > 1.5 and 320 or math.ceil( 480 / aspectRatio ),

height = aspectRatio < 1.5 and 480 or math.ceil( 320 * aspectRatio ),

scale = “letterbox”,

fps = 30,

antialias = false,

xalign = “center”,

yalign = “center”,

imageSuffix = 

{

["@2"] = 2

}

}

}

[/lua]

Thank you.

Is there a reason you’re using GraphicsCompatiblity = 1?

Some screenshots would help.

I am following the tutorials from https://www.udemy.com/mobile-game-development-with-corona/#/lecture/327543 and when the video was made that was the latest version. I am using a storyboard template that i downloaded from the course and in the config.lua file thats what he put.

Do you think that that is a bad practice? I don’t know the differences between #1 and #2 so I don’t know what I am doing differently. Would I have to change much code if I switched to graphics #2?

Well graphics 1.0 is really old.  I’ve not heard about any plans to disable GraphicsCompatibility=1, but at some point we will probably have to remove the technical debt that causes us.  It’s better to go modern.

Rob

So how must I fix this problem? If I switch over to graphics 2.0 that will fix it?

I would still like to see some screen shots of what’s going on.

It’s hard to tell from your description on exactly what’s going on.  You can also print out the values of display.contentWidth and display.contentHeight that might help too.

Rob

The first image is how it is supposed to be, the ball is right on top of the ground. The second image is how it looks like on most of all the other simulators, where the image is much higher than what it is supposed to be.

It may be a problem that my image is 4268 x 674, and I am running into problems trying to downsize that image. The image was created by me, so I can make the image smaller in the vector art program that I am using or I can scale it in corona.

You’re using display.newImage() which loads the image in at its full resolution.  The display.newImageRect() uses our dynamic image selection to pick the right sized image for the device.  It also lets you explicitly say how big each image should be.  Now I would have thought you would have had the bigger images on the iPhone 3gs simulator as opposed to the retina display of the iPhone 4, but I would start there.  See if display.newImageRect() will improve things for you.

When I replace display.newImage() with display.newImageRect I get the error"Attempt to index local ‘ground2’ (a nil value)", which is the first time ground2 is called after display.newImageRect(), with makes me think display.newImageRect() didn’t load the image.

Thank you for helping me this far

Are there any other messages in your terminal window?  Is there more to the backtrace?

Can you post your new code?  You need to make sure you’re passing the right parameters in.  display.newImageRect() requires a width and height of the image to be specified.  If you leave those out you might get a similar error.

Rob

Thank you, this worked.

Is there a reason you’re using GraphicsCompatiblity = 1?

Some screenshots would help.

I am following the tutorials from https://www.udemy.com/mobile-game-development-with-corona/#/lecture/327543 and when the video was made that was the latest version. I am using a storyboard template that i downloaded from the course and in the config.lua file thats what he put.

Do you think that that is a bad practice? I don’t know the differences between #1 and #2 so I don’t know what I am doing differently. Would I have to change much code if I switched to graphics #2?

Well graphics 1.0 is really old.  I’ve not heard about any plans to disable GraphicsCompatibility=1, but at some point we will probably have to remove the technical debt that causes us.  It’s better to go modern.

Rob

So how must I fix this problem? If I switch over to graphics 2.0 that will fix it?

I would still like to see some screen shots of what’s going on.

It’s hard to tell from your description on exactly what’s going on.  You can also print out the values of display.contentWidth and display.contentHeight that might help too.

Rob

The first image is how it is supposed to be, the ball is right on top of the ground. The second image is how it looks like on most of all the other simulators, where the image is much higher than what it is supposed to be.

It may be a problem that my image is 4268 x 674, and I am running into problems trying to downsize that image. The image was created by me, so I can make the image smaller in the vector art program that I am using or I can scale it in corona.

You’re using display.newImage() which loads the image in at its full resolution.  The display.newImageRect() uses our dynamic image selection to pick the right sized image for the device.  It also lets you explicitly say how big each image should be.  Now I would have thought you would have had the bigger images on the iPhone 3gs simulator as opposed to the retina display of the iPhone 4, but I would start there.  See if display.newImageRect() will improve things for you.