This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Negate sideways velocity on an object being acted upon by a Phaser physics engine. | |
* The primary use for this is to simulate vehicle movement by negating "drift" when the vehicle turns. | |
* @param {Phaser.Sprite} sprite The sprite whose sideways velocity you want to negate | |
*/ | |
function stopSidewaysVelocity(sprite) { | |
// Recycle the same object to conserve memory | |
if(!stopSidewaysVelocity.sideways) { | |
stopSidewaysVelocity.sideways = {}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createTree(nodes) { | |
const children = {}; | |
const tree = []; | |
for(const node of nodes) { | |
node.children = children[node.id] || (children[node.id] = []); | |
(node.parent_id ? children[node.parent_id] || (children[node.parent_id] = []) : tree).push(node); | |
} | |
return tree; |