[Solved] How do I get consistant screen dimensions with zoomEven?

Hi,

Trying to do something incredibly simple. I just want to put a rectangle on each side of the screen for use with physics. The app is set to zoomEven.

I have tried every display parameter on the list, but cannot get a consistant result. Hopefully someone can enlighten me.

This is my final code before giving up. The left and top are working fine, but the right, bottom is a severe pain in my rear.

  local side_box_width = 120
  local side_box_height = 0 --will come from screen size
  local top_bottom_box_width = 0 --will come from screen size
  local top_bottom_box_height = 120

  -- Create a vector rectangle sized exactly to the "screen area"
  local area = display.newRect(
      display.screenOriginX, 
      display.screenOriginY,
      display.contentWidth, 
      display.contentHeight
  )

  print(area.x, area.y, area.width, area.height)

  area.isVisible = false

  local left_box = display.newRect(area.x, area.y, side_box_width, area.height)
  local right_box = display.newRect(area.width, area.y, side_box_width, area.height)
  local top_box = display.newRect(area.x, area.y, area.width, top_bottom_box_height)
  local bottom_box = display.newRect(area.x, area.height, area.width, top_bottom_box_height)

Note: They are not centered at the moment, but that is intentional for the testing.

Config snippet:

width = 640,
height = 960, 
scale = "zoomEven",

Thanks in advance for any tips.

-dev

Not sure whether this is what you’re looking for, but:

local side_box_width = 120
  local side_box_height = 0 --will come from screen size
  local top_bottom_box_width = 0 --will come from screen size
  local top_bottom_box_height = 120

  -- Create a vector rectangle sized exactly to the "screen area"
  local area = display.newRect(
      display.screenOriginX, 
      display.screenOriginY,
      display.actualContentWidth, 
      display.actualContentHeight
  )

  print(area.x, area.y, area.width, area.height)

 -- area.isVisible = false

  local left_box = display.newRect(area.x, area.y, side_box_width, area.height):setFillColor(1,0,0)
  local right_box = display.newRect(area.width+display.screenOriginX, area.y, side_box_width, area.height):setFillColor(0,1,0)
  local top_box = display.newRect(area.x, area.y, area.width, top_bottom_box_height):setFillColor(0,0,1)
  local bottom_box = display.newRect(area.x, area.height+display.screenOriginY, area.width, top_bottom_box_height):setFillColor(1,1,0)

Key notes:
For the right and bottom you’ll want to use actualContentWidth and actualContentHeight.
I’m not sure exactly how the numbers differ between letterBox and zoomEven, but to get an accurate position for right and bottom you might also need to add screenOriginX and screenOriginY respectively.

1 Like

I’ve been using my screen module to accomplish that:

When you require my module, you can just access its properties to get the minimum and maximum x and y coordinates for the screen, as well as its width, height, etc.

Also, personally, I’ve always preferred letterbox over other scaling modes.

Bingo! Thank you. I still don’t quite understand so I’m gonna need to study up a bit. :slight_smile:

Thank you for your help, I really appreciate it.

-dev

1 Like

Hi,

I actually have been using screen and I like it very much, but it wasn’t giving me good results either. But probably wasn’t using it correctly looking at the answer above. Historically I do letterbox but I really dislike having any overflow, there is a particular aesthetic to a full screen immersive app that is hard to recreate with letterbox. Screen is now a part of my app toolkit, so thank you for sharing the code. :+1:

Hi,

I just tried again using screen and it works perfectly. :man_facepalming:

Not sure what I missed the first time, but I will never underestimate the power of screen again. :muscle:

-dev

If you’re on Android, it may be an issue with the ”immersiveSticky” mode that takes a moment to kick in, which leads to the screen size changing once it does.