简体   繁体   English

如何获得在argon.js和AFrame中工作的距离触发器?

[英]How to get distance triggers working in argon.js and AFrame?

I'm trying to add distance triggers to an object in my ar-scene, following the code snippet on the project's github page. 我试图按照项目github页面上的代码片段 ,将距离触发器添加到ar场景中的对象。

The following gives me errors in Argon. 以下内容为我提供了Argon中的错误。

<ar-geopose id="GT2" lla=" -84.398881 33.778463" userotation="false" trigger="radius:100;event:alert('You are near GT.');"> </ar-geopose>

Am I calling events incorrectly? 我打错电话了吗?

(This all assumes you are using argon.js and argon-aframe.js from http://argonjs.io ) (所有这些都假设您正在使用http://argonjs.io的 argon.js和argon-aframe.js)

The "event" attribute of your trigger needs to be the name of an event you want to generate, not code to execute. 触发器的“事件”属性必须是要生成的事件的名称,而不是要执行的代码。 The attributes of the components (like trigger) specify parameters (like any CSS attributes), not code. 组件的属性(如触发器)指定参数(如任何CSS属性),而不是代码。

So, you should use something like this in your javascript 因此,您应该在javascript中使用类似这样的内容

trigger="radius:100;event:target_trigger"

This will cause the trigger component to emit("target_trigger") on the entity you've attached it to. 这将使触发器组件在您附加到其上的实体上emit("target_trigger")

You could listen for that by doing something like 你可以通过做类似的事情来听

var GT = document.querySelector("#GT2");

GT.addEventListener('target_trigger', function(evt) {
    alert("you are near GT.");
});

I would avoid using alerts in an AR app, of course, but I assume you're doing this for testing/debugging. 当然,我会避免在AR应用程序中使用警报,但是我假设您正在这样做以进行测试/调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM