PR303在找到和丢失标记时引入事件
您可以通过简单地添加事件侦听器来使用它们:
anchorRef.addEventListener("markerFound", (e)=>{ // your code here}
通过这样的简单设置:
<a-marker id="anchor">
<a-entity>
</a-marker>
这里的例子。请注意,从 9 月 18 日开始,您需要使用dev
分支才能使用上述内容。
ORIGINAL ANWSER - 如果您想手动操作
通过检查标记是否在需要时可见(其他事件或刻度线)来检测是否找到标记是可能的:
if(document.querySelector("a-marker").object3D.visible == true)
例如:
init: function() {
this.marker = document.querySelector("a-marker")
this.markerVisible = false
},
tick: function() {
if (!this.marker) return
if (this.marker.object3D.visible) {
if (!this.markerVisible) {
// marker detected
this.markerVisible = true
}
} else {
if (this.markerVisbile) {
// lost sight of the marker
this.markerVisible = false
}
}
}
正如 adrian li 指出的那样,它不适用于
a-marker-camera
,仅适用于
a-markers