Created
January 16, 2024 20:39
-
-
Save derme302/4b3a0b153e138c2e4d39bcffa08cb8d4 to your computer and use it in GitHub Desktop.
Handle Notched Phones in GameMaker by ChatGPT4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function returns true if the device has a notch, false otherwise | |
function device_has_notch() | |
{ | |
// Get the device model name | |
var device_model = device_get_model(); | |
// Check if the device model is one of the known notched iPhones | |
var notched_iphones = ["iPhone X", "iPhone XS", "iPhone XS Max", "iPhone XR", "iPhone 11", "iPhone 11 Pro", "iPhone 11 Pro Max", "iPhone 12", "iPhone 12 Mini", "iPhone 12 Pro", "iPhone 12 Pro Max"]; | |
return array_find_index(notched_iphones, device_model) != -1; | |
} | |
// This function returns the safe area of the screen as a rectangle | |
function device_get_safe_area() | |
{ | |
// Get the device display size | |
var display_width = display_get_width(); | |
var display_height = display_get_height(); | |
// Check if the device has a notch | |
if (device_has_notch()) | |
{ | |
// Use the iOS safe area values for notched devices | |
// Source: [Updating your GUI for iPhone X and “Notched” Devices](https://www.behance.net/gallery/109643193/Updating-your-GUI-for-iPhone-X-and-Notched-Devices) | |
var safe_x = 44; | |
var safe_y = 44; | |
var safe_w = display_width - 88; | |
var safe_h = display_height - 78; | |
} | |
else | |
{ | |
// Use the full display size as the safe area | |
var safe_x = 0; | |
var safe_y = 0; | |
var safe_w = display_width; | |
var safe_h = display_height; | |
} | |
// Return the safe area as a rectangle | |
return rectangle(safe_x, safe_y, safe_x + safe_w, safe_y + safe_h); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment