Viewable content area doesn't fill screen?

Hi,

I’m having trouble filling the screen with a rectangle using display.viewableContentWidth, and display.viewableContentHeight as size arguments. It only fills part of the screen. Is there something I’m not seeing here?

Here’s the code I’ve attached a pic

[lua]_W = display.viewableContentWidth
_H = display.viewableContentHeight

local background = display.newRect(0, 0, _W, _H)
background:setFillColor(47/255,147/255,84/255)[/lua]

Thanks,

David

The first two arguments for display.newRect() are the x and y coordinates. Since you’ve set this to 0, 0 then the rect will be centred in the top left corner, and three quarters of it will be off screen.

Try this instead:

local background = display.newRect(display.contentCenterX, display.contentCenterY, \_W, \_H)

Use:

  • display.actualContentWidth
  • display.actualContentHeight

Also, I’m assuming you set up your config.lua file correctly, but if not then that will goof you up.

Oh, and 0,0 is the upper left of the design area (not necessarily the screen)

To be very clear, assuming your config.lua is not goofed up:

local cx,cy = display.contentCenterX, display.contentCenterY local fullw,fullh = display.actualContentWidth, display.actualContentHeight local left = cx - fullw/2 local right = cx + fullw/2 local top = cy - fullh/2 local bot = cy + fullh/2 local tmp = display.newRect( left, top, fullw, fullh ) tmp.anchorX = 0 tmp.anchorY = 0 -- or local tmp = display.newRect( cx, cy, fullw, fullh )

Thanks @hasty and @roaminggamer,

That solved the problem. I was following this video at the time …

Corona University - Creating Text Fields in Corona SDK

and it didn’t use the contentCentre arguments.

Cheers,

The first two arguments for display.newRect() are the x and y coordinates. Since you’ve set this to 0, 0 then the rect will be centred in the top left corner, and three quarters of it will be off screen.

Try this instead:

local background = display.newRect(display.contentCenterX, display.contentCenterY, \_W, \_H)

Use:

  • display.actualContentWidth
  • display.actualContentHeight

Also, I’m assuming you set up your config.lua file correctly, but if not then that will goof you up.

Oh, and 0,0 is the upper left of the design area (not necessarily the screen)

To be very clear, assuming your config.lua is not goofed up:

local cx,cy = display.contentCenterX, display.contentCenterY local fullw,fullh = display.actualContentWidth, display.actualContentHeight local left = cx - fullw/2 local right = cx + fullw/2 local top = cy - fullh/2 local bot = cy + fullh/2 local tmp = display.newRect( left, top, fullw, fullh ) tmp.anchorX = 0 tmp.anchorY = 0 -- or local tmp = display.newRect( cx, cy, fullw, fullh )

Thanks @hasty and @roaminggamer,

That solved the problem. I was following this video at the time …

Corona University - Creating Text Fields in Corona SDK

and it didn’t use the contentCentre arguments.

Cheers,