Skip to content

Instantly share code, notes, and snippets.

View maxwihlborg's full-sized avatar

Max Wihlborg maxwihlborg

View GitHub Profile
@maxwihlborg
maxwihlborg / stats.js
Last active August 29, 2015 14:01
Simple FPS Counter for JavaScript games
var stats = {
fps: 0,
frames: 0,
_prevtime: 0,
_ticktime: 0,
_tickint: 100,
_tickval: 0,
_sum: 0,
var canvas = document.createElement("canvas");
canvas.width = 200; canvas.height = 200;
var dispCanvas = document.createElement("canvas");
dispCanvas.width = 400; dispCanvas.height = 400;
var dispCtx = dispCanvas.getContext("2d");
// setup pixel scaling
dispCtx.imageSmoothingEnabled = false;
dispCtx.oImageSmoothingEnabled = false;
@maxwihlborg
maxwihlborg / debounce.js
Created March 1, 2015 15:17
Simple javascript debounce function used when bundling up function calls.
/**
* Simple debounce function; usage:
*
* Create a function that only can be called once every 500 ms
*
* var df = debounce(function() {
* ... func body ...
* }, 500)
*
* Bind the function to an event