adapted some changes from pixi.js dev branch