【发布时间】:2018-01-12 02:57:52
【问题描述】:
所以,我应该从警告开始,我是 AFrame 的新手(尽管不是编程、游戏编程或 Javascript)。我目前正在尝试用基本的 GearVR 控制器交互组合一个简单的场景。
当我说“基本交互”时,我的意思是当你关注 official tutorial 时,我有一个小的启动场景,我只是想扩展它,这样当你按下触发器时,(特别是触发器,而不仅仅是任何按钮),小文本组件的文本值已更改。
长话短说——我的代码不起作用。尽管我在组件 init 函数中添加了事件侦听器(并且我已经确认正在调用 init),但似乎从未调用过侦听器回调。如果我不得不猜测,我会说我附加“激光控制”的实体没有发出“触发”事件,但我不确定如何确认。以下是相关部分:
AFRAME.registerComponent('gearvr-trigger', {
schema: {
textValue: {
default: "Hello WebVR!"
}
},
init: function() {
var message_box = document.querySelector('#message');
var el = this.el;
el.addEventListener('triggerdown', function(evt) {
message_box.setAttribute('value', this.data.textValue);
});
}
});
<a-text id='message' value="Hello, A-Frame!" color="#BBB"
position="-0.9 0.2 -3" scale="1.5 1.5 1.5">
</a-text>
<a-box gearvr-trigger='textValue: "New Text Value";' src='#boxTexture' position='0 2 -5' rotation='0 45 45' scale='2 2 2'>
<a-animation attribute='position' to='0 2.5 -5' direction='alternate' dur='2000' repeat='indefinite'></a-animation>
<a-animation attribute="scale" begin="mouseenter" dur="300" to="2.3 2.3 2.3"></a-animation>
<a-animation attribute="scale" begin="mouseleave" dur="300" to="2 2 2"></a-animation>
<a-animation attribute="rotation" begin="click" dur="2000" to="360 405 45"></a-animation>
</a-box>
<a-entity raycaster='far: 100; showLine: true;' line='color: red;' laser-controls></a-entity>
如果比我更有经验的人看到我做错了什么,那就太好了,但如果你能指出一些响应 GearVR 控制器事件的体面代码示例,我也会很高兴。
【问题讨论】:
-
他们需要指向盒子并按下扳机,还是只需要在指向任何地方时按下扳机?
标签: aframe