Lance JS 库:Spaaace 教程对移动设备上的触摸输入无响应
Lance JS library: Spaaace tutorial unresponsive to touch input on mobile
开始尝试 Lance JS library for building multiplayer games. I can't get the Spaace tutorial 在我的 Android 设备上接受输入,Pixel 2 XL 运行 Android 8.1.0。游戏在我的笔记本电脑上运行良好。
将我的 phone 连接到笔记本电脑时,我在 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';
修复了类型错误。
但游戏仍然无法响应触摸输入。游戏运行,AI船偶尔会飞过我的船并向我的船射击。
感谢您指出这个错误!
看起来它是在 Lance 中首次实现 KeyboardControls 时随 Lance 2.0.0 引入的,并且 Spaaace 教程已更新为使用这些。
解决方案的第一步是像您提到的那样引入 ES6 样式导入。
额外的步骤是遵循与 KeyboardControls 相同的逻辑,并注册实际发送到服务器的输入。只要有手指触摸屏幕,相关输入(向上 + 向左或向右计算)就会被视为 'active' 然后发送。
主代码:
constructor(clientEngine){
....
this.clientEngine.gameEngine.on('client__preStep', ()=>{
for (let keyName in this.activeInput){
if (this.activeInput[keyName]){
this.clientEngine.sendInput(keyName);
}
}
});
}
相关提交是here
查看更新演示:
开始尝试 Lance JS library for building multiplayer games. I can't get the Spaace tutorial 在我的 Android 设备上接受输入,Pixel 2 XL 运行 Android 8.1.0。游戏在我的笔记本电脑上运行良好。
将我的 phone 连接到笔记本电脑时,我在 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';
修复了类型错误。
但游戏仍然无法响应触摸输入。游戏运行,AI船偶尔会飞过我的船并向我的船射击。
感谢您指出这个错误!
看起来它是在 Lance 中首次实现 KeyboardControls 时随 Lance 2.0.0 引入的,并且 Spaaace 教程已更新为使用这些。
解决方案的第一步是像您提到的那样引入 ES6 样式导入。 额外的步骤是遵循与 KeyboardControls 相同的逻辑,并注册实际发送到服务器的输入。只要有手指触摸屏幕,相关输入(向上 + 向左或向右计算)就会被视为 'active' 然后发送。
主代码:
constructor(clientEngine){
....
this.clientEngine.gameEngine.on('client__preStep', ()=>{
for (let keyName in this.activeInput){
if (this.activeInput[keyName]){
this.clientEngine.sendInput(keyName);
}
}
});
}
相关提交是here
查看更新演示: