2017-02-24 8 views
1

私のコンソールが私のクリックイベントハンドラに自分のログステートメントを記録していないのを解明しようとしています。どんな助けでも大歓迎です。なぜaフレームのクリックイベントが機能していないのですか?

ここは私のJSフィドルです。私は、フレームにバージョン5.0ここで

を使用していhttps://jsfiddle.net/tznezkqo/

は、私はあなたがコンポーネントがあることを確認する必要がありますと信じて、私のHTML

<!-- Player --> 
    <a-entity camera universal-controls="movementControls: checkpoint" checkpoint-controls="mode: animate" 
      position="0 1.764 0"> 
    <a-entity cursor="fuse: true; fuseTimeout: 500" position="0 0 -1" 
       geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03;" material="color: #CCC; shader: flat;"> 
    </a-entity> 
    </a-entity> 


    <a-entity id="box" cursor-listener geometry="primitive: box" material="color: blue" position="-2 2.2 -1.5"></a-entity> 

と私のJS

$(document).ready(function() { 

    AFRAME.registerComponent('cursor-listener', { 
    init: function() { 
     this.el.addEventListener('click', function (evt) { 
     console.log('I was clicked at: ', evt.detail.intersection.point); 
     }); 
    } 
    }); 

    AFRAME.registerComponent('collider-check', { 
    dependencies: ['raycaster'], 
    init: function() { 
     this.el.addEventListener('raycaster-intersected', function() { 
     console.log('Player hit something!'); 
     }); 
    } 
    }); 

}); 

答えて

2

ですの前に登録され、の要素が使用されています。 https://jsfiddle.net/pj3m4obt/2/

<script> 
AFRAME.registerComponent('cursor-listener', { 
    init: function() { 
     this.el.addEventListener('click', function (evt) { 
     console.log('I was clicked at: ', evt.detail.intersection.point); 
     }); 
    } 
    }); 
</script> 
<body> 
... 
<a-entity id="box" cursor-listener geometry="primitive: box" material="color: blue" position="-2 2.2 -1.5"></a-entity> 
+0

これは理にかなって:

ここにあなたの例の修正版です。ありがとう 私はちょうど私のシートの底ではなく、頭に私のapp.jsを移動しました。 本当にありがとうございます。 –

関連する問題