代码之家  ›  专栏  ›  技术社区  ›  Martin Omander

Lance JS库:SPAAACE教程对移动设备上的触摸输入无响应

  •  2
  • Martin Omander  · 技术社区  · 8 年前

    开始尝试构建多人游戏的Lance JS库。我无法获取 spaace tutorial 以接受我的Android设备上的输入,一个运行Android 8.1.0的像素2 XL。游戏在我的笔记本电脑上运行良好。

    将手机连接到笔记本电脑时,我在javascript控制台中看到了以下错误消息:

    bundle.js:60989未捕获类型错误:utils.shortestarc is not a function
    位于mobileControls.handlemovementinput(bundle.js:60989)
    在OnRequestAnimationFrame(bundle.js:60921)
    

    在mobilecontrols.js中替换此行

    const utils=require('../common/utils');
    

    用这条线

    import utils from'../common/utils';
    

    修正了类型错误。

    但游戏仍然对触摸输入没有反应。游戏运行,人工智能飞船偶尔飞过并向我的飞船射击。

    .要在我的Android设备上接受输入,需要一个运行Android 8.1.0的像素2 XL。这个游戏在我的笔记本电脑上很好用。

    将手机连接到笔记本电脑时,我在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';
    

    修正了那个类型错误。

    但游戏仍然对触摸输入没有反应。游戏运行和人工智能船偶尔飞过和射击我的船。

    1 回复  |  直到 8 年前
        1
  •  3
  •   OpherV    8 年前

    谢谢你指出这个错误!

    看上去它是在Lance中首次实现键盘控件时随Lance 2.0.0引入的,而SPAAACE教程也被更新以使用这些控件。

    解决方案的第一步是像您提到的那样引入ES6样式的导入。 额外的步骤是遵循键盘控件的相同逻辑,并注册输入到服务器的实际发送。只要有一根手指接触屏幕,相关输入(向上+左或右计算)就被视为“活动”,然后发送。

    主要代码:

    constructor(clientEngine){
    
        ....
    
        this.clientEngine.gameEngine.on('client__preStep', ()=>{
            for (let keyName in this.activeInput){
                if (this.activeInput[keyName]){
                    this.clientEngine.sendInput(keyName);
                }
            }
        });
    
    }
    

    相关承诺是 here

    查看更新演示:

    https://spaaace.herokuapp.com/

    推荐文章