Skip to content

Instantly share code, notes, and snippets.

View drhayes's full-sized avatar
🐱

David Hayes drhayes

🐱
View GitHub Profile
var idableLayers = ['entities', 'switches']
module.exports = function(content) {
this.cacheable && this.cacheable();
var map = JSON.parse(content);
var pathBits = this.resourcePath.split('/');
var mapFilename = pathBits[pathBits.length - 1];
if (map.layers) {
map.layers.forEach(function(layer) {
if (idableLayers.indexOf(layer.name) === -1 ) {
@drhayes
drhayes / README.md
Last active April 16, 2016 02:07
Entity Factory in Phaser with Webpack

entityFactory Overview

I have a lot of classes extending Phaser.Sprite. Building each one by hand via some if statement when loading a tilemap is dumb. Thankfully, webpack is here to rescue me.

Explain

The full code of entityFactory.js is below.

Say you've got a directory full of sprites, each one a subclass of Phaser.Sprite:

@drhayes
drhayes / camera.js
Created November 17, 2015 03:00
Phaser.Camera.js updateTargetTrackSlow
updateTargetTrackSlow() {
// We always have a deadzone. If we don't, that means we haven't set the target yet so
// there's no sense in doing anything in this method yet.
if (!this.deadzone) {
return;
}
this._targetPosition.copyFrom(this.target);
if (this.target.parent) {
this._targetPosition.multiply(this.target.parent.worldTransform.a, this.target.parent.worldTransform.d);
@drhayes
drhayes / buildNative.js
Last active August 28, 2015 19:44
The file that builds my game using nw.js.
// Are you running me from "npm run build-native"? 'Cuz you should.
// Tips:
// * Copy what this guy did: https://github.com/octalmage/Marknote for icons
// and stuff.
// * Turn on devtools by changing "window.toolbar" in package.json to true.
var NwBuilder = require('nw-builder');
var nw = new NwBuilder({
files: [
@drhayes
drhayes / README.md
Last active July 7, 2016 18:04
Scaled, pixel-perfect drawing in Phaser using a second canvas
@drhayes
drhayes / bezier.js
Created January 5, 2015 16:37
bezier curve functions for ImpactJS.
ig.module(
'game.util.bezier'
)
.defines(function() {
'use strict';
// With the help of: http://www.moshplant.com/direct-or/bezier/math.html
// Code totally stolen from processing.js.
// 0 <= t <= 1
@drhayes
drhayes / gist:efcc999154ce2c256a35
Created July 23, 2014 21:32
onename verification
Verifying myself: My Bitcoin username is +drhayes. https://onename.io/drhayes
@drhayes
drhayes / keybase.md
Created June 12, 2014 21:21
keybase.md

Keybase proof

I hereby claim:

  • I am drhayes on github.
  • I am drhayes (https://keybase.io/drhayes) on keybase.
  • I have a public key whose fingerprint is 17C5 BB89 6584 45B1 B431 D800 78E4 6D79 D295 413E

To claim this, I am signing this object:

@drhayes
drhayes / gist:9513977
Created March 12, 2014 19:04
How I'm scaling my 2d Phaser game right now
preload: function() {
game.stage.scale.minWidth = 320;
game.stage.scale.minHeight = 240;
game.stage.scale.maxWidth = 640;
game.stage.scale.maxHeight = 480;
game.stage.scale.pageAlignHorizontally = true;
game.stage.scale.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
game.stage.scale.setShowAll();