Main Page: Difference between revisions
From Virtujoy Documentation
|
|
| (4 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| <h2>Web Sensor API</h2>
| | Ngapain ngintip-ngintip. |
| '''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>
| |
Latest revision as of 07:32, 9 December 2025