mirror of
https://github.com/flynx/Slang.git
synced 2025-10-29 18:50:08 +00:00
added touch support...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a6d2ed5ee1
commit
5b5d3ad8b9
@ -3,6 +3,10 @@
|
|||||||
<style>
|
<style>
|
||||||
|
|
||||||
.snake.field {
|
.snake.field {
|
||||||
|
position: relative;
|
||||||
|
left: 50%;
|
||||||
|
margin-left: -250px;
|
||||||
|
|
||||||
width: 500px;
|
width: 500px;
|
||||||
height: 500px;
|
height: 500px;
|
||||||
border: solid 1px silver;
|
border: solid 1px silver;
|
||||||
@ -300,6 +304,10 @@ function kbHandler(event){
|
|||||||
&& action[0] in Snake
|
&& action[0] in Snake
|
||||||
&& Snake[action[0]].apply(Snake, action.slice(1))
|
&& Snake[action[0]].apply(Snake, action.slice(1))
|
||||||
}
|
}
|
||||||
|
function tapHandler(event){
|
||||||
|
(event.clientX || event.changedTouches[0].pageX) <= (document.body.clientWidth / 2) ?
|
||||||
|
Snake.left()
|
||||||
|
: Snake.right() }
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
@ -348,6 +356,8 @@ function setup(){
|
|||||||
// setup kb handler (only once)...
|
// setup kb handler (only once)...
|
||||||
if(!HANDLER_SET){
|
if(!HANDLER_SET){
|
||||||
document.addEventListener('keydown', kbHandler)
|
document.addEventListener('keydown', kbHandler)
|
||||||
|
//document.addEventListener('click', tapHandler)
|
||||||
|
document.addEventListener('touchstart', tapHandler)
|
||||||
HANDLER_SET = true
|
HANDLER_SET = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -359,14 +369,11 @@ function setup(){
|
|||||||
|
|
||||||
<head> <title>Simple Snake</title> </head>
|
<head> <title>Simple Snake</title> </head>
|
||||||
|
|
||||||
|
|
||||||
<body onload="setup()">
|
<body onload="setup()">
|
||||||
|
|
||||||
<div class="simplesnake"> </div>
|
<div class="simplesnake"> </div>
|
||||||
|
|
||||||
<p>
|
|
||||||
XXX basic instructions...
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
<!-- vim:set ts=4 sw=4 spell : -->
|
<!-- vim:set ts=4 sw=4 spell : -->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user