0 votes

Hello, how to play a music stream at the start of an animation please? Conected my audiostreamplayer with the started animation, added as its script: 'func onAnimationPlayer3animationstarted(change2): play()' but that doesn't play the sound...

I know i should use a function to call the track and play it, but what's the syntax?

in Engine by (321 points)

1 Answer

0 votes

In your AnimationPlayer, when you add a track you can chose Function Call Track. When you add a key to this track, you can define in it a function, that will be called on the node, that you specified the track for, arguments can be passed. So you give that track a function that does

AudiostreamPlayer2D.play()

in a key at the start of your animation.

by (840 points)

Sry, but how to chose the Function call track when addin the track, and definin in it a function? Or are you just talkin about the settin of keys, and their effects, in animation tracks? Cause I've set a playin key at the beginin of my animation, it just don't play it...

Upload your project, i'll show you how.

Upload? A screenshot? Look: https://imgur.com/a/WypGS
You can see my unefective playin track...

No, I mean your project packed as a .rar for exampe, so I can have a close look.

But how to upload it?

https://files.fm/

Btw: You should use google a bit more....

Ok, rarely uploadin files you know.

Here's the link: https://files.fm/u/zkmkpcrh

79MB?! As a zip, for 4 light scenes? How come? What's the weight of a full 3D game??

The solution is rather simple: You actually never started the animation... You either have to hit the little A at the top right corner of the animation panel or you have to start it via script:

AnimationPlayer.play("the_animation", 0, 1) # anim_name, initial offset, speed

Are we talkin of the chaos scene? Cause that's here that I want the audiostream of the 'who' collisionpolygon to start in the animationplayer3.
And the animation start with a play key at the beginin, but without playin the audiostream... With that script in 'who':

extends CollisionPolygon2D

func onArea2Dinputevent( viewport, event, shapeidx ):
if event is InputEventMouseButton:
if event.get
buttonindex() == BUTTONLEFT and event.ispressed():
get
node("AnimationPlayer3").play("change2")

func onAnimationPlayer3animationfinished( change2 ):
gettree().changescene("res://Scenes/Soul.tscn")

func onAnimationPlayer3animationstarted(change2):
AudioStreamPlayer.play()

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.