display_get_orientation

此函数将返回四个常量之一 GameMaker 必须告诉您运行游戏的设备是处于横向模式还是纵向模式(请参阅下表)。

请注意,在 HTML5 目标模块中使用时,此函数可能无法正确检测设备的方向。但是,使用以下脚本很容易模拟这种情况:

return (browser_width < browser_height);

这样的函数对于纵向将返回 true,对于横向将返回 false

 

语法:

display_get_orientation()

 

返回:

显示方向常量

显示方向常量
常量描述
display_landscapeThe device is being held horizontally ie: The longest edge is from left to right, and the menu button is on the right.
display_landscape_flippedAs above, only now the menu button is on the left.
display_portraitThe device is being held vertically ie: The longest edge is from top to bottom, and the menu button is at the bottom.
display_portrait_flippedAs above, only now the menu button is at the top.

 

例子:

if (display_get_orientation() == display_landscape)
{
    global.Config = 0;
}
else
{
    global.Config = 1;
}

上述代码检查设备的方向,并根据返回的值设置全局变量。