Detecting screen rotation on IOS?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
rsheasby
Prole
Posts: 9
Joined: Wed Sep 26, 2018 9:08 pm

Detecting screen rotation on IOS?

Post 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
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Detecting screen rotation on IOS?

Post 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.
rsheasby
Prole
Posts: 9
Joined: Wed Sep 26, 2018 9:08 pm

Re: Detecting screen rotation on IOS?

Post 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
rsheasby
Prole
Posts: 9
Joined: Wed Sep 26, 2018 9:08 pm

Re: Detecting screen rotation on IOS?

Post 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.
rsheasby
Prole
Posts: 9
Joined: Wed Sep 26, 2018 9:08 pm

Re: Detecting screen rotation on IOS?

Post 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?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest