Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to rotate screen on android? — Gideros Forum

How to rotate screen on android?

Hello)
I made an app(years have passed since i made it last time). Gideros has a great evolution, i'm so happy with that.

But i can't understand how to rotate screen on android. It works perfectly on html5 without any string of code it rotates so well. But on android it doesn't rotate at all. Even if i use android:screenOrientation="sensor" - screen rotates but app still have fixed rotation

Comments

  • piepie Member
    It worked for me last time I tried: in Project Properties is "Autorotation - All orientations" enabled?
  • Yes, i set all orientations and it still do not work. Btw html5 works even with Normal orientation.
  • piepie Member
    I think that html5 orientation is handled by the browser, it might have nothing to do with gideros.
    Does it work if you set your app in landscape in project properties?
    Also, take a look here:
    https://forum.gideros.rocks/discussion/7269/code-for-landscape-or-portrait

    https://wiki.gideros.rocks/index.php/Application:getDeviceOrientation

    and you could also listen to
    stage:addEventListener( Event.APPLICATION_RESIZE, self.onApplicationResize, self )

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • Yeah, I already read that.
    But i was impressed how it works in browser and wonder about possibility to make it works on mobile same way

  • unlyingunlying Guru
    edited January 12
    Ok, i'm trying to make it works with code(but still sad that it's not working like in a web).

    But it's not working:( Or i'm doing something wrong.
    print(application:getOrientation())
    application:setOrientation("portrait")
    print(application:getOrientation())
    returns
    landscapeLeft 2
    landscapeLeft 2
    snippet by sinistersoft works even stranger

  • piepie Member
    It seems that application:getDeviceOrientation() doesn't read correctly.

    I wonder if that happens since https://forum.gideros.rocks/discussion/8757/gideros-2024-6-released


    This always reads "portrait" for me even changing player > hardware


    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    Honestly I've always found all this orientation stuff rather difficult to understand.
    Internally Gideros deals with three orientations which are:
    - hardware orientation: supposed to be the fixed native/hardware orientation of the display
    - device orientation: the current orientation of the device, that is whether you currently hold your phone (if allowed to riotate) in portrait or landscape mode or upside down
    - orientation: your app orientation

    Since 2024.6 I tried to stick to the definitions above for every platform (android would soemtimes change hardware orientation along device orientation, or sometimes even app orientation, but perhaps I missed some changes.

    In the player menu, hardware orientation actually changes the fixed hardware orientation, not the device orientation. Thinking about it, it looks wrong...

    Likes: pie

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    Looking at what I changed in 2024.6, I actually made it work as @unlying expects it (I think), that is if you enable autorotation, then app orientation will automatically change to match deviceOrientation. This also means that you no longer can change your app orientation directly, instead calling setOrientation() requests the device to change its orientation first.
  • piepie Member
    Thank you @hgy29 , I assumed that changing Hardware Orientation in gideros player was like changing the physical orientation of your device.

    However to answer @unlying I just tried this on android player on my device with gideros 2025.1.1 and getDeviceOrientation works as expected.

    What I am not sure is why I have to call application setOrientation to rotate the screen, but I might have built my player with "normal orientation" instead of "all orientations" enabled in project properties.
     
    local orientation = application:getDeviceOrientation()
     
    local demoText = TextField.new(nil, orientation)
    demoText:setScale(4)
    demoText:setPosition(200, 200)
    stage:addChild(demoText)
     
     
    function appResize(event)
    	local tmpOrientation = application:getDeviceOrientation()
    	if tmpOrientation ~= orientation then
    		orientation = tmpOrientation
    		demoText:setText(orientation)
    		application:setOrientation(orientation)
    	end
    	print(orientation, tmpOrientation)
    end
     
    stage:addEventListener(Event.APPLICATION_RESIZE, appResize )

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.