I am trying to create an A-frame scene that allows for "onclick" events if the device used to view is mobile, but that relies on keypresses for laptop/desktop.
When I use "if(this.el.isMobile)" in one component function, if the answer is false, it seems to stop any other component function from executing as well? I have tested this - and if I instead use "if(false)" in the below code in the "clickhandler" function it still allows keypresses in the "keyDownPress" function, but if I use "if(this.el.isMobile)" the "keyDownPress" function doesn't execute either.
Is this a bug or have I messed up? The documentation doesn't give too much information (from what I could find) as to what isMobile is doing behind the scenes.
<!DOCTYPE html>
<html>
<head></head>
<body>
<!DOCTYPE html>
<html>
<head></head>
<body>
<!--Load a-frame-->
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
<!--Input logging events-->
<script>
//Register keypress
AFRAME.registerComponent('keypress', {
init: function() {
window.addEventListener('keydown', this.keyDownPress);
},
keyDownPress: function(evt) {
//If keypress is left - change box colour to blue
if (evt.keyCode === 37) {
this.color = "blue";
}
}
});
//Register Generic Click Events for phone
AFRAME.registerComponent('clickhandler', {
init: function() {
this.el.addEventListener('mousedown', function(evt) {
if (this.el.isMobile) {
//Code here to do stuff on click if mobile
}
});
}
});
</script>
<!--A-Frame VR Scene-->
<a-scene clickhandler>
<a-entity camera keypress></a-entity>
<a-sky></a-sky>
</a-scene>
</body>
</html>
</body>
</html>