Main Page: Difference between revisions
From Virtujoy Documentation
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
< | <h2>Web Sensor API</h2> | ||
'''Sensor API''' mengekspos fungsionalitas sensor device hardware.[https://developer.mozilla.org/en-US/docs/Web/API/Sensor_APIs] Mungkin kita bisa mengembangkan web app yang mengumpulkan data sensor dan mengirimkannya ke server game? | |||
Catatan: Sensor API hanya didukung browser tertentu (misalnya Chrome). | |||
== | <syntaxhighlight lang="html" line> | ||
<ul> | |||
<li id="gyroscope-x"></li> | |||
<li id="gyroscope-y"></li> | |||
<li id="gyroscope-z"></li> | |||
</ul> | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="javascript" line> | |||
if (typeof Gyroscope === "undefined") { | |||
alert("Gyroscope API not supported on this device/browser.") | |||
} | |||
else { | |||
const gyroscope = new Gyroscope({ frequency: 60 }); | |||
const gyroscopeLabelX = document.querySelector("#gyroscope-x"); | |||
const gyroscopeLabelY = document.querySelector("#gyroscope-y"); | |||
const gyroscopeLabelZ = document.querySelector("#gyroscope-z"); | |||
gyroscope.addEventListener("reading", (e) => { | |||
gyroscopeLabelX.innerText = `Angular velocity along the X-axis ${gyroscope.x}`; | |||
gyroscopeLabelY.innerText = `Angular velocity along the Y-axis ${gyroscope.y}`; | |||
gyroscopeLabelZ.innerText = `Angular velocity along the Z-axis ${gyroscope.z}`; | |||
}); | |||
gyroscope.start(); | |||
} | |||
</syntaxhighlight> | |||
Revision as of 11:26, 13 September 2025
Web Sensor API
Sensor API mengekspos fungsionalitas sensor device hardware.[1] Mungkin kita bisa mengembangkan web app yang mengumpulkan data sensor dan mengirimkannya ke server game?
Catatan: Sensor API hanya didukung browser tertentu (misalnya Chrome).
<ul>
<li id="gyroscope-x"></li>
<li id="gyroscope-y"></li>
<li id="gyroscope-z"></li>
</ul>
if (typeof Gyroscope === "undefined") {
alert("Gyroscope API not supported on this device/browser.")
}
else {
const gyroscope = new Gyroscope({ frequency: 60 });
const gyroscopeLabelX = document.querySelector("#gyroscope-x");
const gyroscopeLabelY = document.querySelector("#gyroscope-y");
const gyroscopeLabelZ = document.querySelector("#gyroscope-z");
gyroscope.addEventListener("reading", (e) => {
gyroscopeLabelX.innerText = `Angular velocity along the X-axis ${gyroscope.x}`;
gyroscopeLabelY.innerText = `Angular velocity along the Y-axis ${gyroscope.y}`;
gyroscopeLabelZ.innerText = `Angular velocity along the Z-axis ${gyroscope.z}`;
});
gyroscope.start();
}