Skip to content

Instantly share code, notes, and snippets.

@pixelhijack
pixelhijack / phaserjs-extended-sprite-subscribe-to-event.js
Last active October 4, 2016 20:07
[Phaser.js] Extended / custom sprites subscribe to event
function Game(){
/*
Then in your gamestate.create you add a Phaser.Signal
with which you can dispatch events:
*/
var lizardman,
eventChannel = new Phaser.Signal();
@pixelhijack
pixelhijack / phaserjs-extended-sprite-listen.js
Created October 4, 2016 19:30
[Phaser.js] Extended / custom sprites which listens to events
function Lizardman(game, x, y, sprite){
this.game = game;
Phaser.Sprite.call(this, game, x, y, sprite);
this.game.add.existing(this);
this.game.physics.enable(this, Phaser.Physics.ARCADE);
this.anchor.setTo(0.5, 0.5);
}
@pixelhijack
pixelhijack / phaserjs-extended-sprite.js
Last active October 4, 2016 18:52
[Phaser.js] Extended / custom sprites
function Lizardman(game, x, y, sprite){
this.game = game;
Phaser.Sprite.call(this, game, x, y, sprite);
this.game.add.existing(this);
this.game.physics.enable(this, Phaser.Physics.ARCADE);
this.anchor.setTo(0.5, 0.5);
}
var MODEL = (function(m){
m.num = 10;
return m;
}(MODEL || {}));
var UI = (function(ui, model, setter){
ui.public = setter;
ui.DOM = (function(){
var priv = model.num * ui.public;
return{
@pixelhijack
pixelhijack / CSS3 basic animation syntax
Created October 28, 2014 13:53
CSS3 basic animation syntax
@-webkit-keyframes popIn {
0% { opacity: 0; transform: scale(.3);}
100% { opacity: 1; transform: scale(1);}
}
@keyframes popIn {
0% { opacity: 0; transform: scale(.3);}
100% { opacity: 1; transform: scale(1);}
}
@pixelhijack
pixelhijack / protractor findElement
Created October 27, 2014 15:56
protractor findElement
var ptor = protractor.getInstance(),
driver = ptor.driver;
var findByName = function(name) {
return driver.findElement(protractor.By.name(name));
};
// showtime!
ptor.driver.get('/Test/Index');
ptor.driver.findElement(protractor.By.xpath('/html/body/div/div[1]/section/input')).sendKeys('whatever');
@pixelhijack
pixelhijack / javascript stack trace anywhere
Created October 20, 2014 08:41
javascript stack trace anywhere
/*
It's well know how to print a stack trace after catching an exception/error in Javascript.
But what if you are not catching anything?
You see something happening at a particular line in code,
but you want to know what's the code path through which the control flow reached that line when that interesting thing happened.
In other words, you want to know what's the stack trace (series of function calls, starting from beginning of the program),
at that particular line of code.
http://www.codeovertones.com/2011/08/how-to-print-stack-trace-anywhere-in.html
*/
@pixelhijack
pixelhijack / String converter translationtable
Last active August 29, 2015 14:06
String converter translationtable
/*
https://code.google.com/p/jslibs/wiki/JavascriptTips
*/
function CreateTranslator(translationTable) function(s) s.replace(new RegExp([k for (k in translationTable)].join('|'), 'g'), function(str) translationTable[str]);
// usage:
var translationTable = { a:1, bb:2, b:3, c:4 };
var MyTranslater = CreateTranslator( translationTable );
function RandomString(length) {
var str = '';
for ( ; str.length < length; str += Math.random().toString(36).substr(2) );
return str.substr(0, length);
}
@pixelhijack
pixelhijack / Javascript array shuffle
Created September 23, 2014 12:28
Javascript array shuffle
var list = [1,2,3,4,5,6,7,8,9];
list = list.sort(function() Math.random() - 0.5);