natiny.window.set_orientation

Lua
natiny.window.set_orientation(win, allowed)

Sets the screen orientations that an Android device may use for the window.

Parameters

Name Type Description
win number Window handle from natiny.window.create
allowed number Nonzero mask of the orientation constants below, combined with bitwise OR (|)

Orientations

Constant Meaning
natiny.window.ORIENTATION_PORTRAIT Portrait with the device in its natural orientation
natiny.window.ORIENTATION_PORTRAIT_FLIPPED Reverse portrait
natiny.window.ORIENTATION_LANDSCAPE Landscape with the device in its natural rotation
natiny.window.ORIENTATION_LANDSCAPE_FLIPPED Reverse landscape
natiny.window.ORIENTATION_ANY Any portrait or landscape orientation

One constant locks the screen to one orientation. Combining constants allows the device to rotate between them. After a rotation, natiny.window.get_width and natiny.window.get_height report the new dimensions.

Example

Lua
local win = natiny.window.create("My Game", 1280, 720)

-- Allow both landscape orientations, but no portrait orientation.
natiny.window.set_orientation(win,
    natiny.window.ORIENTATION_LANDSCAPE |
    natiny.window.ORIENTATION_LANDSCAPE_FLIPPED)

Notes

  • The call has no effect on desktop or web builds.
  • A zero mask or a mask containing bits outside natiny.window.ORIENTATION_ANY is rejected with a diagnostic message and leaves the current policy unchanged.
  • Android cannot represent combinations such as portrait plus one landscape orientation. Natiny maps such combinations to all four orientations.
  • The Android system rotation lock can prevent an allowed rotation.
  • natiny.window.get_orientation returns the current orientation, not the allowed mask.
  • The APK manifest controls the initial orientation. This call changes the policy after the program starts.
  • Rotating recreates the Android drawable, but existing Natiny handles remain valid.