summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.js7
-rw-r--r--public/javascripts/game.js14
2 files changed, 13 insertions, 8 deletions
diff --git a/app.js b/app.js
index 4656530..d6c2a6c 100644
--- a/app.js
+++ b/app.js
@@ -187,7 +187,9 @@ io.sockets.on('connection', function (socket) {
count: user.count,
connected: now,
current: 0,
- active: true
+ active: true,
+ x: -9999,
+ y: -9999
};
io.sockets.emit('count', {
@@ -198,6 +200,9 @@ io.sockets.on('connection', function (socket) {
});
socket.on('mouse', function(data){
+ if (! socket.user || ! data || ! data.x || ! data.y) return;
+ users[socket.user.id].x = data.x;
+ users[socket.user.id].y = data.y;
io.sockets.volatile.emit('mouse', data);
});
diff --git a/public/javascripts/game.js b/public/javascripts/game.js
index f088988..8672f23 100644
--- a/public/javascripts/game.js
+++ b/public/javascripts/game.js
@@ -114,13 +114,14 @@ var UI = {
}
}
for (var i in data.users) {
+ var user = data.users[i];
if (!( i in users )) {
- users[i] = data.users[i];
+ users[i] = user;
}
- if (i != _id && ! users[i].cursor) {
- var cursor = new Cursor( users[i], now );
- users[i].cursor = cursor;
- cursors.push(cursor);
+ if (i != _id && ! user.cursor) {
+ var cursor = new Cursor( user, now );
+ user.cursor = cursor;
+ user.cursor.el.css({ 'margin-right': -user.x, 'margin-bottom': -user.y });
}
else if (i == _id) {
own_cursor.name.html( users[i].firstname );
@@ -170,13 +171,12 @@ function Cursor ( user, now ) {
cursors.push(base);
if (user.active) {
- console.log(">>>>", base.initial, now, user.connected, now - user.connected)
base.initial += now - user.connected;
} else {
base.blur();
}
- console.log(now, base.start, base.initial, base.delay);
+ // console.log(now, base.start, base.initial, base.delay);
}
base.update = function(now){