Skip to content

Instantly share code, notes, and snippets.

View drhayes's full-sized avatar
🐱

David Hayes drhayes

🐱
View GitHub Profile
@drhayes
drhayes / Gruntfile.js
Created April 16, 2013 04:39
sprite multitask config
sprite: {
'media/player.png': [
'build/player-idle001.png',
'build/player-kneel001.png',
'build/player-kneel002.png',
'build/player-kneel003.png',
'build/player-kneel004.png',
'build/player-kneel005.png',
'build/player-walk001.png',
'build/player-walk002.png',
@drhayes
drhayes / Gruntfile.js
Last active December 16, 2015 06:39
Custom sprite multitask
var NUM_SPRITE_COLS = 6;
var gm = require('gm');
grunt.registerMultiTask('sprite', 'Sprite images', function() {
var images = this.data;
var numRows = Math.ceil(images.length / NUM_SPRITE_COLS);
var sprite = gm('');
sprite.tile(NUM_SPRITE_COLS + 'x' + numRows);
sprite.quality('100');
sprite.background('transparent');
@drhayes
drhayes / gist:4997048
Created February 20, 2013 16:55
Pre-commit hook to remove trailing whitespace on lines you've actually changed
#
# Shamelessly copied from http://blog.yesmeck.com/archives/make-git-automatically-remove-trailing-whitespace-before-committing/
#
# What's distinct about this version, as opposed to several I've seen,
# is that it only fixes the whitespace on lines you've actually changed,
# so avoids making you the blamee of code you didn't change.
# Find files with trailing whitespace
for file in `git diff --check --cached | grep '^[^+-]' | grep -o '^.*[0-9]\+:'` ; do
file_name=`echo ${file} | grep -o '^[^:]\+'`
@drhayes
drhayes / eventChain.js
Created January 15, 2013 07:14
EventChain's repeat method
update.repeat = function(times) {
times = times || Infinity;
var originalTimes = times;
var stepsCopy;
steps.push(function() {
times -= 1;
if (times > 0) {
var args = stepsCopy.slice(0);
args.unshift(1, 0);
[].splice.apply(steps, args);
@drhayes
drhayes / eventChain.js
Created January 15, 2013 05:48
EventChain's last lines
// Returned from this constructor thing.
return update;
};
});
@drhayes
drhayes / eventChain.js
Created January 14, 2013 16:38
EventChain's every method
update.every = function(sec, doThis) {
update.during(
new EventChain()
.wait(sec)
.then(doThis)
.repeat()
);
return this;
};
@drhayes
drhayes / eventChain.js
Created January 14, 2013 06:33
EventChain's during function
update.during = function(doThis) {
if (!steps) {
throw new Error('during only works with previous step!');
}
var func = steps[steps.length - 1];
steps[steps.length - 1] = function() {
doThis();
func();
};
return this;
@drhayes
drhayes / eventChain.js
Created January 14, 2013 06:28
EventChain's wait function
update.wait = function(secs) {
var decrement = secs;
steps.push(function() {
// Update.
if (decrement) {
decrement -= ig.system.tick;
}
// End.
if (decrement <= 0) {
steps.shift();
@drhayes
drhayes / eventChain.js
Created January 14, 2013 06:20
EventChain's then function
update.then = function(doThis) {
steps.push(function() {
// Update.
doThis();
// End.
steps.shift();
});
return this;
}
@drhayes
drhayes / eventChain.js
Created January 14, 2013 05:59
EventChain: The Basics
// Defines a function that can fire sequential events.
EventChain = function() {
// Make sure we get called with new.
if (this === window) {
return new EventChain();
}
var steps = [];
// Called every frame.