Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Sets the direction the sprite faces based on it's velocity.
- * Faces the sprite in it's opposite direction when velocity is < 0
- * Assumes the sprite is facing right when its horizontal scale is < 0
- *
- * @param sprite The sprite to set the direction of. Must have arcade physics enabled on it.
- */
- function setSpriteDirection(sprite: Phaser.Sprite) {
- let horVelocity = sprite.body.velocity.x;
- let horScale = sprite.scale.x;
- let velSign = GeneralHelpers.signum(horVelocity);
- let scaleSign = GeneralHelpers.signum(horScale);
- if (horVelocity !== 0 && scaleSign !== velSign) {
- let absScale = Math.abs(horScale);
- sprite.scale.x = velSign === 1 ? absScale : absScale * -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement