-1
\$\begingroup\$

I am following the tutorial for Phaser 3 game development and came across the following line of code.

player.anims.play('Left', true);

I am curious about the Boolean parameter here. What is the purpose of "true"? I searched through the API documents but was unable to find it. Thanks!

\$\endgroup\$
0
0
\$\begingroup\$

The documentation for the play method reads:

play(key [, ignoreIfPlaying] [, startFrame])
Plays an Animation on a Game Object that has the Animation component, such as a Sprite.

Animations are stored in the global Animation Manager and are referenced by a unique string-based key.

Parameters:

Name Type Argument Default Description
key string | Phaser.Animations.Animation The string-based key of the animation to play, as defined previously in the Animation Manager. Or an Animation instance.
ignoreIfPlaying boolean false If this animation is already playing then ignore this call.
startFrame integer 0 Optionally start the animation playing from this frame index.

So, true in the second argument says that if this same animation specified in key is already playing, don't interrupt it to execute the animation described in this call. If you pass false instead, then this animation call will stop the current animation - even if it's the one specified in key - and take over with the animation you've specified, starting at startFrame.

\$\endgroup\$
0
\$\begingroup\$

I found the answer in this link as quoted below.

"Just wanted to expound upon this answer, for anyone who stumbles across this in the future. That second parameter on anims.play is named "ignoreIfPlaying." If false, whichever animation is currently playing will stop, even if it's the animation you intend to play. If true, then if you're already playing that animation it will continue.It's false by default, so you can omit the second argument entirely."

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.