Gamepad: thuộc tính displayId
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
Thuộc tính chỉ đọc displayId của giao diện Gamepad trả về VRDisplay.displayId của VRDisplay được liên kết - tức là VRDisplay mà gamepad đang điều khiển cảnh được hiển thị.
Một Gamepad được xem là có liên kết với một VRDisplay nếu nó báo cáo một tư thế nằm trong cùng không gian với tư thế của màn hình, xem VRDisplay.getPose().
Note: Thuộc tính này là một phần của WebVR API cũ. Nó đã bị thay thế bởi WebXR Gamepads Module.
Không có phương án thay thế trực tiếp cho thuộc tính này. Đối tượng Gamepad liên kết với một XRInputSource có thể được lấy bằng thuộc tính XRInputSource.gamepad.
Giá trị
Một số biểu thị VRDisplay.displayId được liên kết. Nếu số là 0, thì gamepad không liên kết với màn hình VR.
Ví dụ
window.addEventListener("gamepadconnected", (e) => {
if (!e.gamepad.displayId) {
console.log("Gamepad connected");
} else {
console.log(
`Gamepad connected, associated with VR display ${e.gamepad.displayId}`,
);
}
});
Đặc tả kỹ thuật
Thuộc tính này là một phần của WebVR API cũ đã bị thay thế bởi WebXR Gamepads Module. Nó không còn nằm trên lộ trình trở thành một tiêu chuẩn.
Cho đến khi tất cả trình duyệt đã triển khai các WebXR APIs mới, bạn nên dựa vào các framework như A-Frame, Babylon.js hoặc Three.js, hoặc một polyfill, để phát triển các ứng dụng WebXR có thể hoạt động trên mọi trình duyệt. Hãy đọc hướng dẫn Porting from WebVR to WebXR của Meta để biết thêm thông tin.