Time require for checking a value

Hello,

When I try to print the value of display.screenOriginY, the result depends if it’s calculated " too quick " by the program.

Why ?

On my huawei y6 device, (pixel perfect on my build.setting file) I know I have this :

display.screenOriginY= - 24 ( same size of my statusBar’s height )

display.actualContentHeight = 640

display.contentHeight = 592 ( = 640 - 24 - 24 (from the bottom too))

local t=display.newText({text="", x=100, y=100 ,fontSize=30}) Runtime:addEventListener("system",function(event)   if event.type=="applicationStart" then     t.text=display.screenOriginY.."/onStartEvent" --It's 0 !   end end)

timer.performWithDelay( 500, function() t.text=display.screenOriginY.."/after 500 ms"  end) --0 again timer.performWithDelay( 2000, function() t.text=display.screenOriginY.."/after 2000 ms"  end) --And now it's -24 (correct value)

Is there a " best " method to get this value ? ( after doing a transition to a first composer for example )

The system listener don’t ( ! ) give the right value ??

(I was thinking that the applicationStart event occur after reading the whole main.lua file.)

Perhaps it’s because the program take a long to load the display library to take the “screenOriginY” value ?

Thanks,

Yvan

If your config.lua is pixel perfect for the device, display.screenOriginY should be 0.  Are you setting any thing regarding the status bar like hiding or showing it? Setting the ImmersiveSticky setting?  

Rob

yes the status bar is hidden

display.setStatusBar(display.HiddenStatusBar)

my config.lua file

if not display then return end local w, h = display.pixelWidth, display.pixelHeight local modes = {1, 1.5, 2, 3, 4, 6, 8} -- Scaling factors to try local contentW, contentH = 320, 480 -- Minimal size your content can fit in -- Try each mode and find the best one local \_w, \_h, \_m = w, h, 1 for i = 1, #modes do local m = modes[i] local lw, lh = w / m, h / m if lw \< contentW or lh \< contentH then break else \_w, \_h, \_m = lw, lh, m end end -- If scaling is not pixel perfect (between 1 and 2) - use letterbox if \_m \< 2 then local scale = math.max(contentW / w, contentH / h) \_w, \_h = w \* scale, h \* scale end application = { content = { width = \_w, height = \_h, scale = 'letterbox', fps = 30, imageSuffix = {['@2x'] = 1.1,['@4x'] = 2.1,} }, licence= { google={key="",},--pour les achats In App de google }, } -- Uncomment to use the common content scaling --[[application = { content = { width = 320, height = 480, scale = 'letterbox', fps = 60, imageSuffix = { ['@2x'] = 1.1, ['@4x'] = 2.1, } } } --]]

seen as your device is 1280x720px then just set width and height accordingly and stop all the crazy calculations in config.lua.  It is just asking for trouble!

That’s not the answer of the question.
It’s work the same with other’s devices ( apple too ) and 1280x720 gives the same situation.

OK well you know best eh? carry on banging your head against a wall… good luck with that

Share your sample project with us so we can look at it.

i.e. Zip up the whole sample you made and share a link to the zip.

Ok I find, the pixel perfect config lua works perfecly, and gives a 0,0 for the display.screenOriginY and X.

But when we call 

native.setProperty('androidSystemUiVisibility', 'immersiveSticky') -- immersive the same

it’s resize the screen, and the value of the originiY change to 0 from -24.

(display.actualContentHeight change also)

And this change does not happen directly after the applicationStart event : if I put immersiveSticky on the first line of main.lua file,

native.setProperty('androidSystemUiVisibility', 'immersiveSticky') local t=display.newText({text="original value "..display.screenOriginY,x=200,y=100}) -- = 0 Runtime:addEventListener("system",function(event) &nbsp; if event.type=="applicationStart" then &nbsp; &nbsp; t.text=t.text.."\nvalue after the read of all main.lua :"..display.screenOriginY -- = 0 &nbsp; &nbsp; timer.performWithDelay( 3000, function() &nbsp; &nbsp; &nbsp; t.text=t.text.."\nvalue after 3 seconds :"..display.screenOriginY -- = -24 &nbsp; &nbsp; end) &nbsp; end end)

so with a rectangle in a game, it’s better to only use " 0 " as the y-origin of the rect instead of display.screenOriginY, because sometimes the rectangle moves 24 from top.

But this still not explain the delay for changing the value of display.screenOriginY in the the timer.

Yvan.

Again, the best way to get help with complex issues like this is to make a small sample project that only demonstrates/replicated the issue, zip it, and share the link with us so we can see it all.

You’re only showing us the parts you think are of importance, but I suspect more is going on here in your code.

It’s really not that complicated. If you hide the status bar then obviously you have changed the screen dimensions.

You won’t see the change in main.lua as your app hasn’t finished loading yet.

You should use the resize () event to redraw your app after setting immersiveSticky.

If your config.lua is pixel perfect for the device, display.screenOriginY should be 0.  Are you setting any thing regarding the status bar like hiding or showing it? Setting the ImmersiveSticky setting?  

Rob

yes the status bar is hidden

display.setStatusBar(display.HiddenStatusBar)

my config.lua file

if not display then return end local w, h = display.pixelWidth, display.pixelHeight local modes = {1, 1.5, 2, 3, 4, 6, 8} -- Scaling factors to try local contentW, contentH = 320, 480 -- Minimal size your content can fit in -- Try each mode and find the best one local \_w, \_h, \_m = w, h, 1 for i = 1, #modes do local m = modes[i] local lw, lh = w / m, h / m if lw \< contentW or lh \< contentH then break else \_w, \_h, \_m = lw, lh, m end end -- If scaling is not pixel perfect (between 1 and 2) - use letterbox if \_m \< 2 then local scale = math.max(contentW / w, contentH / h) \_w, \_h = w \* scale, h \* scale end application = { content = { width = \_w, height = \_h, scale = 'letterbox', fps = 30, imageSuffix = {['@2x'] = 1.1,['@4x'] = 2.1,} }, licence= { google={key="",},--pour les achats In App de google }, } -- Uncomment to use the common content scaling --[[application = { content = { width = 320, height = 480, scale = 'letterbox', fps = 60, imageSuffix = { ['@2x'] = 1.1, ['@4x'] = 2.1, } } } --]]

seen as your device is 1280x720px then just set width and height accordingly and stop all the crazy calculations in config.lua.  It is just asking for trouble!

That’s not the answer of the question.
It’s work the same with other’s devices ( apple too ) and 1280x720 gives the same situation.

OK well you know best eh? carry on banging your head against a wall… good luck with that

Share your sample project with us so we can look at it.

i.e. Zip up the whole sample you made and share a link to the zip.

Ok I find, the pixel perfect config lua works perfecly, and gives a 0,0 for the display.screenOriginY and X.

But when we call 

native.setProperty('androidSystemUiVisibility', 'immersiveSticky') -- immersive the same

it’s resize the screen, and the value of the originiY change to 0 from -24.

(display.actualContentHeight change also)

And this change does not happen directly after the applicationStart event : if I put immersiveSticky on the first line of main.lua file,

native.setProperty('androidSystemUiVisibility', 'immersiveSticky') local t=display.newText({text="original value "..display.screenOriginY,x=200,y=100}) -- = 0 Runtime:addEventListener("system",function(event) &nbsp; if event.type=="applicationStart" then &nbsp; &nbsp; t.text=t.text.."\nvalue after the read of all main.lua :"..display.screenOriginY -- = 0 &nbsp; &nbsp; timer.performWithDelay( 3000, function() &nbsp; &nbsp; &nbsp; t.text=t.text.."\nvalue after 3 seconds :"..display.screenOriginY -- = -24 &nbsp; &nbsp; end) &nbsp; end end)

so with a rectangle in a game, it’s better to only use " 0 " as the y-origin of the rect instead of display.screenOriginY, because sometimes the rectangle moves 24 from top.

But this still not explain the delay for changing the value of display.screenOriginY in the the timer.

Yvan.

Again, the best way to get help with complex issues like this is to make a small sample project that only demonstrates/replicated the issue, zip it, and share the link with us so we can see it all.

You’re only showing us the parts you think are of importance, but I suspect more is going on here in your code.

It’s really not that complicated. If you hide the status bar then obviously you have changed the screen dimensions.

You won’t see the change in main.lua as your app hasn’t finished loading yet.

You should use the resize () event to redraw your app after setting immersiveSticky.