Path Follower Rotation Offset
Demonstrates how to apply a rotation offset to a sprite following a path, allowing you to adjust its orientation relative to the direction of travel.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('lemming', 'assets/sprites/lemming.png');
}
create ()
{
const curve = new Phaser.Curves.Line(new Phaser.Math.Vector2(100, 100), new Phaser.Math.Vector2(600, 400));
const graphics = this.add.graphics();
graphics.lineStyle(1, 0xffffff, 0.5);
curve.draw(graphics);
const lemming = this.add.follower(curve, 100, 100, 'lemming');
lemming.startFollow({
duration: 5000,
yoyo: true,
repeat: -1,
rotateToPath: true,
rotationOffset: 90
});
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#2d2d2d',
parent: 'game-container',
scene: Example
};
const game = new Phaser.Game(config);