I'm trying to make a web app that gets accelerometer data from the device and play different audio according to the XYZ orientation, is there a way to achieve this in ZIM?
Hi @Gloria - yes - you should be able to get Orientation with a Frame event. Permission needs to be gotten first - at least on Apple, and possibly Android - can't remember. But we have PermissionAsk() at https://zimjs.com/docs.html?item=PermissionAsk there is an example there with deviceorientation. Also see the Tilt entry which talks about both devicemotion and deviceorientation https://zimjs.com/docs.html?item=Tilt
// on iOS, the sensors must be allowed first - this example works for all devices
const label = new Label().center();
const permissionType = "deviceorientation"; // or "devicemotion"
const ask = new PermissionAsk(init, permissionType);
function init(yes) {
// if the user answers yes to the PermissionAsk
const errorPane = new Pane("SENSOR not available",yellow);
if (yes) {
// use the sensors
label.text = decimals(e.rotation.x) +","+ decimals(e.rotation.y) +","+ decimals(e.rotation.z);
S.update();
} else { // answered no to PermissionAsk dialog
errorPane.show();
}
}