Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的javascript构建的touchevents游戏延迟(cordova)_Javascript_Android_Cordova_Phonegap Build - Fatal编程技术网

我的javascript构建的touchevents游戏延迟(cordova)

我的javascript构建的touchevents游戏延迟(cordova),javascript,android,cordova,phonegap-build,Javascript,Android,Cordova,Phonegap Build,这是我的游戏 我已经在KitKat、棒棒糖和棉花糖上测试了这个应用程序。这个游戏在棒棒糖和棉花糖的触摸事件上落后,但在KitKat中效果很好。我发现这种声音在棒棒糖和棉花糖中效果很好,但在KitKat中却不起作用 我所说的滞后是指它停止大约半秒钟。我寻找这个问题。我发现浏览器中的事件有300毫秒的延迟。所以我使用了Fast Click.js…但问题仍然存在 var-app={ //应用程序构造函数 初始化:函数(){ 这是bindEvents(); }, //绑定事件侦听器 // //绑定启动

这是我的游戏

我已经在KitKat、棒棒糖和棉花糖上测试了这个应用程序。这个游戏在棒棒糖和棉花糖的触摸事件上落后,但在KitKat中效果很好。我发现这种声音在棒棒糖和棉花糖中效果很好,但在KitKat中却不起作用

我所说的滞后是指它停止大约半秒钟。我寻找这个问题。我发现浏览器中的事件有300毫秒的延迟。所以我使用了Fast Click.js…但问题仍然存在

var-app={
//应用程序构造函数
初始化:函数(){
这是bindEvents();
},
//绑定事件侦听器
//
//绑定启动时所需的任何事件。常见事件包括:
//“加载”、“deviceready”、“脱机”和“联机”。
bindEvents:function(){
文件.addEventListener('devicerady',this.ondevicerady,false);
},
//deviceready事件处理程序
//
//“this”的作用域是事件。要调用“receivedEvent”
//函数,我们必须显式调用“app.receivedEvent(…);”
ondevicerady:function(){
app.receivedEvent(“DeviceRady”);
},
//在接收到的事件上更新DOM
receivedEvent:函数(id){
var parentElement=document.getElementById(id);
var listeningElement=parentElement.querySelector('.listening');
var receivedElement=parentElement.querySelector('.received');
setAttribute('style','display:none;');
setAttribute('style','display:block;');
console.log('接收到的事件:'+id);
}
};
app.initialize();
/*此处我的代码*/var stp=0;var gameover、playtore、taptoplay;
localStorage.highscore=0;
风险值水平=-1.5;
我的配子;
var myObstacle=[];
我的背景;
var myScore;
var得分=0;
var scoreUpdater=[];
var-myLevel;
var火箭=[];
var X=$(window.width();
变量Y=$(窗口).height();
var myGameArea={//它是由canvas元素和start函数组成的游戏区域。。。。。
画布:document.createElement(“画布”),
开始:函数(){
this.canvas.width=$(window.width();//100%;//window.innerwidth;
this.canvas.height=$(window.height();//100%;//window.innerheight;
this.context=this.canvas.getContext(“2d”);
document.body.insertBefore(this.canvas,document.body.childNodes[0]);/?????????????????????????????
这个.frameno=0;
this.interval=setInterval(updateGameArea,20);
},
清除:函数(){
this.context.clearRect(0,0,this.canvas.width,this.canvas.height);
},
停止:函数(){
clearInterval(这个.interval);
}
}
函数calx(a){
返回(a*360)/480;
}
功能caly(b){
申报表(b*600)/270;
}
//播放音频
//
功能播放音频(url){
//在url播放音频文件
var my_media=新媒体(url,
//成功回调
函数(){
log(“playAudio():音频成功”);
},
//错误回调
功能(err){
log(“playAudio():音频错误:+err”);
}
);
//播放音频
我的媒体播放();
}
函数startName(){
myGamePiece=新组件(193*0.25161*0.25,“img/superman.png”,10120,“imagec”);/*67*1.6*/*14*1.6*///宽度、高度、颜色、位置……super3.png…50/20
myBackground=新组件(1500800,“img/backspace.png”,0,0,“背景”);
myScore=新组件(“30px”,“Consolas”,“purple”,5,25,“text”);//X-170,25
myLevel=新组件(“30px”、“控制台”、“紫色”、X-140,25、“文本”);
mySound=新声音(“sounds/burst.mp3”);
mysnd=新声音(“sounds/score.wav”);
//var media=新媒体(“sounds/burst.mp3”,onSuccess,onError);//[mediaStatus]);
//scoreUpdater[0]=新组件(62.7*0.8,36.8*0.8,“img/scoreUpdater.png”,90153,“image”);
//火箭[0]=新组件(52,76,“img/rocket.png”,50,50,“image”);
//myObstacle[0]=新成分(10400,“红色”、钙(300)、钙(120),“n”);
myGameArea.start();//添加画布元素并将其作为元素的第一个子节点插入。。。。。
}
功能组件(宽度、高度、颜色、x、y、类型)
{
this.type=type;
如果(类型==“图像”| |类型==“背景”| |类型==“图像C”)
{
this.image=新图像();
this.image.src=color;
}
这个。宽度=宽度;
这个。高度=高度;
这个.x=x;
这个。y=y;
这个.speedY=0;
这个。speedX=0;
this.update=函数()
{
ctx=myGameArea.context;
if(this.type==“text”)
{
ctx.font=this.width+“”+this.height;
ctx.fillStyle=颜色;
ctx.fillText(this.text,this.x,this.y);
}
if(this.type==“image”| | this.type==“background”| | this.type==“imagec”)
{   
/*如果(this.image.src==“img/rocket.png”)/?????????????????????????????????????????????????
{
this.image.src=“img/rocketflip.png”;
}*/
drawImage(this.image,this.x,this.y,this.width,this.height);
if(this.type==“后台”)
{//ctx.scale(-1,1);
drawImage(this.image,this.x+this.width,this.y,this.width,this.height);
//ctx.刻度(-1,1);
}
}
其他的
{ctx.fillStyle=color;
ctx.fillRect(this.x,this.y,this.width,this.height);
}
}
this.newPos=函数()
{
if(this.type==“imagec”)/&&this.image.src==“super3.png”)
{
if(此.xY此.height)
{
如果(这个.x

您可以尝试以下方法:

var touchmove = false;
$(window).on("touchmove",function(){
    touchmove = true;
});

$(window).on("touchend",function(e){
    if (!touchmove){
        e.preventDefault();
        e.stopPropagation();
        e.target.click();
    }
        else{
            touchmove = false;
        }
});

但是你应该在你的应用程序中将可点击的对象作为链接,这样可以在所有环境中直接触发点击。

请在你的问题中加入以下细节:-滞后现象仅发生在棒棒糖中吗?-在应用程序中发生了什么