Skip to content

Instantly share code, notes, and snippets.

@lilgreenland
Created September 11, 2017 03:00
Show Gist options
  • Save lilgreenland/021cb3f9a288d0e6e5691366281a98fd to your computer and use it in GitHub Desktop.
Save lilgreenland/021cb3f9a288d0e6e5691366281a98fd to your computer and use it in GitHub Desktop.
canvas template (full screen)
<!--
for the non full screen version
https://codepen.io/lilgreenland/pen/zKVXxo -->
<canvas id="canvas-full"></canvas>
var canvas = document.getElementById('canvas-full');
var ctx = canvas.getContext("2d");
function setupCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
setupCanvas();
window.onresize = function() {
setupCanvas();
};
//___________________get mouse input___________________
/* var mouse = {
down: false,
x: 0,
y: 0
};
document.onmousemove = function(e) {
mouse.x = e.clientX;
mouse.y = e.clientY;
}
document.onmousedown = function() {
mouse.down = true;
console.log(mouse);
};
document.onmouseup = function() {
mouse.down = false;
}; */
//___________________get keyboard input___________________
// var keys = [];
// document.onkeydown = function(e){
// keys[e.keyCode] = true;
// //console.log(e.keyCode);
// }
// document.onkeyup = function(e){
// keys[e.keyCode] = false;
// }
// const cycle = function() {
// ctx.clearRect(0, 0, canvas.width, canvas.height); //clear
// window.requestAnimationFrame(cycle);
// };
// window.requestAnimationFrame(cycle);
body{
overflow:hidden;
}
canvas {
position: absolute;
top: 0;
left: 0;
z-index: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment