Skip to content

Instantly share code, notes, and snippets.

@d33pfri3d
Created July 3, 2012 12:56
Show Gist options
  • Save d33pfri3d/3039577 to your computer and use it in GitHub Desktop.
Save d33pfri3d/3039577 to your computer and use it in GitHub Desktop.
Multitouch
var i = 0;
var numTouches = 0;
function touch( ev ) {
i++;
var out = document.getElementById('out');
if( ev.type == 'touchstart' ) {
out.value += i + ': touch start\n';
numTouches++;
}
else {
out.value += i + ': touch end\n';
numTouches--;
}
document.getElementById('indicator').style.backgroundColor
= (numTouches == 2) ? '#8e6' : '#fb7';
//~ alert(numTouches)
out.scrollTop = out.scrollHeight;
ev.stopPropagation();
ev.preventDefault();
return false;
}
var ta = document.getElementById('ta');
ta.addEventListener('touchstart', touch, false);
ta.addEventListener('touchend', touch, false);
<!DOCTYPE html>
<html>
<head>
<title>Multitouch Test</title>
<meta name="viewport" content="width=device-width; initial-scale=1; maximum-scale=1; user-scalable=0;"/>
</head>
<body>
<textarea style="width: 300px; height: 150px;" id="out"></textarea>
<div style="width:300px; height: 16px; background-color: #fb7; margin: 8px 0;" id="indicator"></div>
<div id="ta" style="background-color: #bde; width:300px; height:100px;">
<p><em>Touch here; See instructions below.</em></p>
</div>
<div style="width:300px;">
<ol>
<li>Hold one finger down in the blue area above</li>
<li>Touch straight down with another finger - don't move your fingers on the surface</li>
<li>Lift your second finger and repeat step 2.</li>
</ol>
<p>When two simultaneous touches are registered, the orange bar will turn green.</p>
<p>For me, about 1 in 3 touches with the second finger has serious lag or is not recognized at all until I move my fingers.</p>
<p>Try it a few times!</p>
<p>
This bug is a serious show stopper for HTML5 Gaming: you can't press two buttons at the same time.
For a real example, try playing <a href="http://playbiolab.com/">Biolab Disaster</a>, you can't
jump (reliably) when running.
</p>
<p><strike>This bug seems to exist only on the (my?) iPad (iOS 4.2.1). It works perfectly on my iPhone 3GS (iOS 4.1).</strike></p>
<p><strong>Update:</strong> Upgraded my iPhone to iOS 4.2.1 and now have the same problem. This seems to be an issue with iOS 4.2.1. At least it's not a hardware bug.</p>
<p><strong>Update (2011-10-13):</strong> Still not fixed in iOS5. Apple, you really suck at this whole developer relations thing, but you couldn't care less, right?</p>
<p><strong>Update (2012-05-16):</strong> Still not fixed in iOS5.1.1.</p>
<p><strong>Update (2012-06-13):</strong> Still not fixed in iOS6.0</p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment