8000 touch example scope · GameJs/gamejs@cc802f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc802f4

Browse files
committed
touch example scope
1 parent 902fce2 commit cc802f4

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

examples/touch/main.js

+31-30
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,40 @@ function colorForTouch(touch) {
2121
return color;
2222
}
2323

24-
// keep track of the ongoing touches
25-
var onGoingTouches = {};
26-
function touchDown(event) {
27-
event.touches.forEach(function(touch) {
28-
onGoingTouches[touch.identifier] = touch;
29-
onGoingTouches[touch.identifier].color = colorForTouch(touch);
30-
// draw circle at start
31-
gamejs.graphics.circle(display, '#ff0000', touch.pos, 5);
32-
});
33-
};
24+
function main() {
25+
// minus margin and footer
26+
var display = gamejs.display.setMode([document.body.clientWidth-50, window.innerHeight-120]);
3427

35-
function touchUp(event) {
36-
event.touches.forEach(function(touch) {
37-
onGoingTouches[touch.identifier] = undefined;
38-
// draw circle at end
39-
gamejs.graphics.circle(display, '#ff0000', touch.pos, 5);
40-
})
41-
};
4228

43-
function touchMotion (event) {
44-
event.touches.forEach(function(touch) {
45-
// keep track of previous and current position
46-
var aTouch = onGoingTouches[touch.identifier];
47-
aTouch.lastPos = aTouch.pos;
48-
aTouch.pos = touch.pos;
49-
// draw movement
50-
gamejs.graphics.line(display, aTouch.color, aTouch.lastPos, aTouch.pos, 3);
51-
})
52-
};
29+
// keep track of the ongoing touches
30+
var onGoingTouches = {};
31+
function touchDown(event) {
32+
event.touches.forEach(function(touch) {
33+
onGoingTouches[touch.identifier] = touch;
34+
onGoingTouches[touch.identifier].color = colorForTouch(touch);
35+
// draw circle at start
36+
gamejs.graphics.circle(display, '#ff0000', touch.pos, 5);
37+
});
38+
};
5339

54-
function main() {
55-
// minus margin and footer
56-
var display = gamejs.display.setMode([document.body.clientWidth-50, window.innerHeight-120]);
40+
function touchUp(event) {
41+
event.touches.forEach(function(touch) {
42+
onGoingTouches[touch.identifier] = undefined;
43+
// draw circle at end
44+
gamejs.graphics.circle(display, '#ff0000', touch.pos, 5);
45+
})
46+
};
47+
48+
function touchMotion (event) {
49+
event.touches.forEach(function(touch) {
50+
// keep track of previous and current position
51+
var aTouch = onGoingTouches[touch.identifier];
52+
aTouch.lastPos = aTouch.pos;
53+
aTouch.pos = touch.pos;
54+
// draw movement
55+
gamejs.graphics.line(display, aTouch.color, aTouch.lastPos, aTouch.pos, 3);
56+
})
57+
};
5758

5859
gamejs.event.onTouchDown(touchDown);
5960
gamejs.event.onTouchUp(touchUp);

0 commit comments

Comments
 (0)
0