Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't collapse events it breaks multi-touch. Also make tick event

  • Loading branch information...
commit 62c8aac61b9457159918d6726993b155c5cc3bf8 1 parent a7ab7ed
@creationix authored
Showing with 8 additions and 18 deletions.
  1. +2 −6 examples/Chaser.js
  2. +6 −12 sdl.js
View
8 examples/Chaser.js
@@ -89,11 +89,7 @@ for (var i = 0; i < numPlayers; i++) {
new Player(i);
}
-var before = Date.now();
-setInterval(function () {
- var after = Date.now();
- var delta = after - before;
- before = after;
+SDL.events.on('tick', function (delta) {
// Check for collisions
var collision = false;
for (var i = 0; i < numPlayers - 1; i++) {
@@ -119,7 +115,7 @@ setInterval(function () {
SDL.flip(screen);
-}, 10);
+});
SDL.events.on("QUIT", function (evt) { process.exit(0); }); // Window close
SDL.events.on("KEYDOWN", function (evt) {
View
18 sdl.js
@@ -7,23 +7,17 @@ Object.defineProperty(SDL, 'events', {
get: function () {
if (events) return events;
events = new (require('events').EventEmitter);
+ var now = Date.now();
setInterval(function () {
+ var after = Date.now();
+ var delta = after - now;
+ now = after;
var data;
- var motion = {};
while (data = SDL.pollEvent()) {
- if (data.type.substr(data.type.length - 6) === "MOTION") {
- motion[data.type] = data;
- continue;
- }
events.emit(data.type, data);
- events.emit("event", data);
}
- Object.keys(motion).forEach(function (name) {
- var event = motion[name];
- events.emit(event.type, event);
- events.emit("event", event);
- });
- }, 13);
+ events.emit('tick', delta);
+ }, 16);
return events;
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.