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.
  • Android cannot represent combinations such as portrait plus one landscape orientation. Natiny maps such combinations to all four orientations.