Page 1 of 1

[Solved] Problem with graphics.getDimensions on Android

Posted: Sun Dec 11, 2022 2:34 pm
by Bigfoot71
Hello everyone ! :D

I'm facing a small problem with the love.graphics.getDimensions function on Android, I wrote myself a small script to resize the game according to the resolution which roughly looks like this:

Code: Select all

local lg = love.graphics

Display = {

    size  = {
        w = WIN_W,  -- Where WIN_* is the original game size
        h = WIN_H
    },

    scale = {
        x = 1,
        y = 1
    }

}

function Display:render(drawable, ...)
    lg.push(); lg.scale(self.scale.x, self.scale.y)
    drawable(...); lg.pop()
end

function Display:resize()
    local size, scale = self.size, self.scale
    size.w, size.h = lg.getDimensions()
    scale.x = size.w / WIN_W
    scale.y = size.h / WIN_H
end
On PC it works very well, the problem occurs on Android where the navigation bar (the Home, Return buttons, etc.) does not always take the same time to hide and therefore I sometimes get the screen size without the bar and other times with the bar, which means that once in two the buttons, joystick, etc. find themselves out of step with the rest of the display (I use GOOI for the GUI elements).

I tried several hacks but without success, if anyone has a solution to this problem that would be great!

Re: Problem with graphics.getDimensions on Android

Posted: Sun Dec 11, 2022 2:40 pm
by darkfrei
Call function setMode twice:
https://love2d.org/wiki/love.window.setMode

Code: Select all

love.window.setMode( width, height, flags )
love.window.setMode( width, height, flags )
Don't forget the safe area:
https://love2d.org/wiki/love.window.getSafeArea

Re: Problem with graphics.getDimensions on Android

Posted: Sun Dec 11, 2022 2:54 pm
by Bigfoot71
darkfrei wrote: Sun Dec 11, 2022 2:40 pm Call function setMode twice:
https://love2d.org/wiki/love.window.setMode

Code: Select all

love.window.setMode( width, height, flags )
love.window.setMode( width, height, flags )
Don't forget the safe area:
https://love2d.org/wiki/love.window.getSafeArea
Oh yeeeah, thank you very much for this quick answer, it works wonderfully!

Re: Problem with graphics.getDimensions on Android

Posted: Sun Dec 11, 2022 3:45 pm
by darkfrei
Bigfoot71 wrote: Sun Dec 11, 2022 2:54 pm
darkfrei wrote: Sun Dec 11, 2022 2:40 pm Call function setMode twice:
https://love2d.org/wiki/love.window.setMode

Code: Select all

love.window.setMode( width, height, flags )
love.window.setMode( width, height, flags )
Don't forget the safe area:
https://love2d.org/wiki/love.window.getSafeArea
Oh yeeeah, thank you very much for this quick answer, it works wonderfully!
I've added this solution to the wiki, but it was deleted.
ms-mad.png
ms-mad.png (473 Bytes) Viewed 928 times