ported code to phaser