user2805226
user2805226

Reputation:

phonegap app with 'touchstart' still very slow

Im making an app in html5 and converting it to an apk with phonegap.

For now you only have to alternately push the left div and the right div. and when you do it your score wil get higher.

The problem is when i press them very fast the score wont change. It will only change upto a certain speed wich is very slow.

leftt = left div, rightt is right div code:

// JavaScript Document
window.onload = function ()
{
var left= 0;
var right= 1;
var score =0;
var el = document.getElementById("leftt");
var el2 = document.getElementById("rightt");





el.addEventListener("touchstart", function(e) {
    if(right ==1)
    {
    left=1;
    right=0;
    score++;
    document.getElementById("score").innerHTML= score;
}
});


el2.addEventListener("touchstart", function(e) {
        if(left ==1)
    {
        left=0;
        right=1;
            score++;
        document.getElementById("score").innerHTML= score;
    }
});

}

Upvotes: 0

Views: 871

Answers (2)

Matt Gaunt
Matt Gaunt

Reputation: 9821

You should add the 'user-scalable=no' parameter to your viewport.

This will remove the 300ms delay that some browsers will add to your web application to account to double clicks (The fastclick library will actually turn itself off if it detects this scenario- https://github.com/ftlabs/fastclick).

There is a lot more in depth on this topic on HTML5Rocks - http://updates.html5rocks.com/2013/12/300ms-tap-delay-gone-away

While this article is applicable to Chrome for Android, the user-scalable=no trick has been in Chrome for some time and is in the Android WebView in KitKat.

Upvotes: 1

Peter Drinnan
Peter Drinnan

Reputation: 4532

There is a bug with Android version 4.0.4+ .Try turning off hardware acceleration for your webview with this line of code in your app java file:

super.appView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

This may be fixed as of 4.4 (KitKat uses Chromeview rather than webview).

Upvotes: 0

Related Questions