[英]Change Press Space Bar to Onscreen Button on Mobile
I'm trying out a shooter game using aframe. 我正在尝试使用Aframe进行射击游戏。
I would like the bullet component in the following code to be created with an on screen button, instead of spacebar. 我希望以下代码中的项目符号组件使用屏幕上的按钮而不是空格键来创建。
AFRAME.registerComponent('gun', {
schema: {
bulletTemplate: {default: '#bullet-template'},
triggerKeyCode: {default: 32} // spacebar
},
init: function() {
var that = this;
document.body.onkeyup = function(e){
if(e.keyCode == that.data.triggerKeyCode){
that.shoot();
}
}
},
shoot: function() {
this.createBullet();
},
createBullet: function() {
var el = document.createElement('a-entity');
el.setAttribute('networked', 'template:' + this.data.bulletTemplate);
el.setAttribute('remove-in-seconds', 3);
el.setAttribute('forward', 'speed:0.3');
var tip = document.querySelector('#player');
el.setAttribute('position', this.getInitialBulletPosition(tip));
el.setAttribute('rotation', this.getInitialBulletRotation(tip));
var scene = document.querySelector('a-scene');
scene.appendChild(el);
},
Looks like this works: 看起来像这样:
init: function() {
var that = this;
document.getElementById("shootbutton").onclick = function(e){
that.shoot();
}
},
With HTML: 使用HTML:
<button id="shootbutton" style="float: right;height: 50px;width: 100px;font-size : 19px;color:red;">SHOOT</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.