-
Notifications
You must be signed in to change notification settings - Fork 1
camera
This module provides interaction with the device's camera.
These are the functions in this module:
This function brings up the camera to take a picture.
Note
On iOS devices, permissions will be requested automatically. Android developers already have the required permissions added to the manifest by the extension: android.permission.READ_EXTERNAL_STORAGE, android.permission.WRITE_EXTERNAL_STORAGE, android.permission.CAMERA.
This function operates asynchronously, which means that it does not immediately return the requested result. Instead, upon completion of the task, it will trigger the Social Async Event.
Syntax:
MobileUtils_Camera_Open()
Returns:
N/A
Triggers:
| Key | Type | Description |
|---|---|---|
| type | String | The string "MobileUtils_Camera_Open"
|
| path | String | The path to the photo |
| success | Boolean | Whether a picture was taken |
Example:
var _read = "android.permission.READ_EXTERNAL_STORAGE";
var _write = "android.permission.WRITE_EXTERNAL_STORAGE";
var _camera = "android.permission.CAMERA";
if(os_type == os_ios or os_check_permission(_write) and os_check_permission(_read) and os_check_permission(_camera))
{
MobileUtils_Camera_Open();
}
else
{
if(!os_check_permission(_write) and !os_check_permission(_read))
os_request_permission(_write, _read);
if(!os_check_permission(_camera))
os_request_permission(_camera);
}The code sample above triggers the mobile device camera overlay that will allow users to take a photo. This photo path can be later caught inside a Social Async Event.
if(async_load[?"type"] == "MobileUtils_Camera_Open")
{
var _path = async_load[?"path"];
Obj_MobileUtils_Camera_Picture.sprite = sprite_add(_path, 0, 0, 0, 0, 0);
}The code above matches the response against the correct event type and loads the newly taken photo.
GameMaker 2024