Is there a way to pause/play the parallax background in flame-engine?

Viewed 135

In my game, I have a parallax background which animates when the player is moving. I want the parallax to stop when the player is not moving. Is it possible?

1 Answers

The ParallaxComponent from Flame just wraps a Parallax object that controls everything. This class has a baseVelocity property that should always be set to the velocity of the player (in case the player can change velocities arbitrarily). If the player can only either move (with same speed) or stop, you can just set it to 0 or not 0.

final c = ParallaxComponent();

// you can do this on your `update` method setting it to `player.velocity`
c.parallax?.baseVelocity = Vector2.zero();
// if `parallax` is null it just means it has not been loaded yet
Related