Page 1 of 1

Detecting screen rotation on IOS?

Posted: Wed Sep 26, 2018 9:14 pm
by rsheasby
Hi all. Very new to Love2d and enjoying it so far. Just screwing around with mobile game dev and I've run into a problem with gyroscope access on iPad. I have an iPad mini and I've made a super basic game that just moves a circle around on the screen in the direction you tilt it. Seems to work fine but the problem is that the iPad doesn't invert the sensor data when you flip the screen. So if the ipad orientation is wrong then the circle moves uphill. Is there any way to detect the screen orientation so that you can invert the sensor data if it's flipped? My current code is as follows:

Code: Select all

local accel
x, y = 100, 100
speed = 1000

function love.load()
    accel = love.joystick.getJoysticks()[1]
end

function love.update(dt)
    a1, a2 = accel:getAxes()
    y = y + a1 * speed * dt
    x = x + -a2 * speed * dt
end

function love.draw()
    love.graphics.circle("fill", x, y, 25)
end

Re: Detecting screen rotation on IOS?

Posted: Thu Sep 27, 2018 5:32 am
by bobbyjones
Use the call back love.resize and print the arguments. Iirc on iOS when the rotation is set to auto the resize call back will be called. You can also set the orientation using setWindow I believe.

Re: Detecting screen rotation on IOS?

Posted: Thu Sep 27, 2018 11:24 am
by rsheasby
bobbyjones wrote: Thu Sep 27, 2018 5:32 am Use the call back love.resize and print the arguments. Iirc on iOS when the rotation is set to auto the resize call back will be called. You can also set the orientation using setWindow I believe.
Doesn't seem to work. Note that the rotation I'm talking about is rotating from horizontal to the opposite direction horizontal. Not talking about horizontal to portrait so I suspect the dimensions never actually change as it's just flipping the image. Here's my code:

Code: Select all

text = "No events yet..."

function love.resize(w, h)
    text = w + " " + h
end

function love.draw()
    love.graphics.print(text, 20, 20)
end

Re: Detecting screen rotation on IOS?

Posted: Thu Sep 27, 2018 11:58 am
by rsheasby
Note that the event does get called if I enable t.window.resizable and if I go between portrait and landscape mode but it still does nothing if I go directly between landscape to opposite landscape or portrait to opposite portrait.

Re: Detecting screen rotation on IOS?

Posted: Thu Sep 27, 2018 12:18 pm
by rsheasby
It seems it's a problem with SDL on iOS. https://discourse.libsdl.org/t/sdl-2-0- ... tion/20701
It only submits events on portrait-landscape changes, not on flips. Surely somebody else has done this sort of thing before using SDL? There must be a way to detect a flip or make the sensor data automatically flip?