开始尝试构建多人游戏的Lance JS图书馆。我无法让Spaace教程接受我的安卓设备上的输入,这是一个运行Android8.1.0的Pixel2XL。游戏在我的笔记本电脑上运行得很好。
当我的手机连接到我的笔记本电脑时,我在Javascript控制台中看到了以下错误消息:
bundle.js:60989 Uncaught TypeError: Utils.shortestArc is not a function
at MobileControls.handleMovementInput (bundle.js:60989)
at onRequestAnimationFrame (bundle.js:60921)在MobileControls.js中替换这一行
const Utils = require('../common/Utils');用这条线
import Utils from '../common/Utils';修正了那个TypeError。
但是游戏仍然对触摸输入没有反应。游戏开始了,AI飞船偶尔飞过,向我的飞船射击。

发布于 2018-06-26 15:14:03
谢谢你指出这个错误!
看起来它是在Lance2.0.0中引入的,当KeyboardControls首次在Lance中实现时,Spaaace教程进行了更新以使用这些教程。
解决方案的第一步是像您提到的那样引入ES6风格的导入。额外的步骤是遵循相同的KeyboardControls逻辑,并将实际的输入发送到服务器。只要有一个手指触摸屏幕,相关的输入(向上+计算左或右)被认为是‘活动’,然后发送。
主要代码:
constructor(clientEngine){
....
this.clientEngine.gameEngine.on('client__preStep', ()=>{
for (let keyName in this.activeInput){
if (this.activeInput[keyName]){
this.clientEngine.sendInput(keyName);
}
}
});
}相关的提交是这里
查看更新演示:
https://stackoverflow.com/questions/50955593
复制相似问题