Skip to content

Instantly share code, notes, and snippets.

@nornagon
Created November 5, 2010 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nornagon/665005 to your computer and use it in GitHub Desktop.
Save nornagon/665005 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>blah</title>
<script src="../socket.io/socket.io.js"></script>
<script src="jquery-1.4.4rc2.js"></script>
<script src="main.js"></script>
<style>
canvas#canvas {
position: absolute;
left: 0;
top: 0;
background: black;
}
</style>
</head>
<body>
<canvas id='canvas'>
</canvas>
</body>
</html>
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
var mouse = {
x: 0, y: 0,
};
function getCoords(e) {
if (e.offsetX) {
return { x: e.offsetX, y: e.offsetY };
}
else if (e.layerX) {
return { x: e.layerX, y: e.layerY };
}
else {
return { x: e.pageX - cb_canvas.offsetLeft, y: e.pageY - cb_canvas.offsetTop };
}
}
$(document).ready(function () {
var socket = new io.Socket('localhost', {transports: ['websocket', 'htmlfile', 'xhr-multipart', 'xhr-polling']})
//socket.connect()
socket.on("connect", function () { console.log("connected using " + socket.getTransport().type) })
socket.on("message", function () { console.log("message") })
var canvas = $('#canvas');
$(window).resize(function () {
canvas[0].width = window.innerWidth;
canvas[0].height = window.innerHeight;
});
canvas[0].width = window.innerWidth;
canvas[0].height = window.innerHeight;
canvas.mousemove(function (ev) {
var x = ev.pageX - canvas[0].offsetLeft,
y = ev.pageY - canvas[0].offsetTop;
mouse.x = x;
mouse.y = y;
});
canvas.mousedown(function (ev) {
var x = ev.pageX - canvas[0].offsetLeft,
y = ev.pageY - canvas[0].offsetTop;
});
canvas.touchstart(function (ev) {
alert("hi!");
});
$(window).keydown(function (ev) {
console.log(ev.keyCode);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment