Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Support for rotating device — Gideros Forum

Support for rotating device

My game is in portrait. I've started adding support for rotating the device; right, left or upside down. I use Letterbox scale mode.

What is the best way of doing this? It feels like I'm going down a long and complicated route:

1. Catch the Event.APPLICATION_RESIZE event
2. Use application:getDeviceOrientation() to check which orientation the app has
3. Rotate Stage accordingly, and reposition all visual elements and hitboxes

Is there a more straightforward way of achieving the same thing?
My Gideros games: www.totebo.com

Comments

  • Use auto rotate in the project settings, enable the requires setting so both portrait and landscape work. If you add a sprite to the screen and have that centered, add all your other sprites as children to it - so the origin is in the middle of the screen.

    If the screen needs rotating you just need to adjust the position of the single sprite to the new centered position. Then you only need to adjust the clipping value for the screen (if you clip differently than standard) and adjust things in the UI that may be out of scope for the screen - eg the score, etc... everything else should look ok.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • totebototebo Member
    edited January 2018
    Thanks @SinisterSoft, will have another bash. Is the expected behaviour that the screen will automatically rotate (so that I don't have to manually rotate stage)? If so there is something up.

    Aha, not sure if I've also enabled the required flag. Is there a reason why it needs to be set in properties AND the required plugin?

    In any case, will double check and report back.
    My Gideros games: www.totebo.com
  • In properties it will rotate to to the opposite view, if you want all 4 rotations then tick that AND also tick the option in requires. :)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Okay, makes sense!
    My Gideros games: www.totebo.com
  • totebototebo Member
    edited January 2018
    I've gone back to the project and set the required flags. It still behaves the same. Is this the expected behaviour? On Android.

    1. Game starts in portrait
    2. Device is turned
    3. There is a brief "turning" animation (probably part of Android)
    4. The visual content stays in the same place, as if the phone hadn't been turned

    The main question is: Do I have to rotate the content manually, or should the auto turning deal with this? I would have assumed the latter.

    In a test project, this is a screenshot in portrait (sorry, the background is white so looks a bit confusing):

    image

    And in landscape:
    image

    If the device is turned upside down, the content is rotated accordingly. Strange! Project settings attached.
    Screenshot_20180130-132404.png
    1440 x 2560 - 16K
    Screenshot_20180130-132407.png
    2560 x 1440 - 14K
    Screen Shot 2018-01-30 at 13.24.49.png
    1724 x 1208 - 278K
    Screen Shot 2018-01-30 at 13.24.25.png
    1188 x 1384 - 202K
    My Gideros games: www.totebo.com
  • Send me the test project and I'll take a look for you.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Got it working! You indeed need to manually set the orientation when you receive the APPLICATION_RESIZE event with Application:setOrientation( orientation ). Sorted!


    My Gideros games: www.totebo.com
    +1 -1 (+2 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    Accepted Answer
    You're welcome. ;)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • totebototebo Member
    edited January 2018
    Sorry, forgot the person who nailed this one was The One, The Only, the Man Who Makes the Impossible Possible, A Legend of Legends... @SinisterSoft!!!

    Likes: SinisterSoft

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
  • :D
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.