Skip to content

Commit

Permalink
touch example scope
Browse files Browse the repository at this point in the history
  • Loading branch information
oberhamsi committed Jun 2, 2014
1 parent 902fce2 commit cc802f4
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions examples/touch/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,40 @@ function colorForTouch(touch) {
return color;
}

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

function touchUp(event) {
event.touches.forEach(function(touch) {
onGoingTouches[touch.identifier] = undefined;
// draw circle at end
gamejs.graphics.circle(display, '#ff0000', touch.pos, 5);
})
};

function touchMotion (event) {
event.touches.forEach(function(touch) {
// keep track of previous and current position
var aTouch = onGoingTouches[touch.identifier];
aTouch.lastPos = aTouch.pos;
aTouch.pos = touch.pos;
// draw movement
gamejs.graphics.line(display, aTouch.color, aTouch.lastPos, aTouch.pos, 3);
})
};
// keep track of the ongoing touches
var onGoingTouches = {};
function touchDown(event) {
event.touches.forEach(function(touch) {
onGoingTouches[touch.identifier] = touch;
onGoingTouches[touch.identifier].color = colorForTouch(touch);
// draw circle at start
gamejs.graphics.circle(display, '#ff0000', touch.pos, 5);
});
};

function main() {
// minus margin and footer
var display = gamejs.display.setMode([document.body.clientWidth-50, window.innerHeight-120]);
function touchUp(event) {
event.touches.forEach(function(touch) {
onGoingTouches[touch.identifier] = undefined;
// draw circle at end
gamejs.graphics.circle(display, '#ff0000', touch.pos, 5);
})
};

function touchMotion (event) {
event.touches.forEach(function(touch) {
// keep track of previous and current position
var aTouch = onGoingTouches[touch.identifier];
aTouch.lastPos = aTouch.pos;
aTouch.pos = touch.pos;
// draw movement
gamejs.graphics.line(display, aTouch.color, aTouch.lastPos, aTouch.pos, 3);
})
};

gamejs.event.onTouchDown(touchDown);
gamejs.event.onTouchUp(touchUp);
Expand Down

0 comments on commit cc802f4

Please sign in to comment.