Topic was automatically imported from the old Question2Answer platform.
Asked By
Rem
Hello,
So I have created 1 animation named « DetachThisPart » with an animationPlayer. (Really easy).
Now I want to know how I can call this animation in C++.
The idea is to make an if :
if(ThisValue=1) {
playAnimation(DetachThisPart);
}
Thanks for your help.
public class Character : KinematicBody2D
{
private AnimatedSprite _animatedSprite;
public override void _Ready()
{
_animatedSprite = GetNode<AnimatedSprite>("AnimatedSprite");
}
public override _Process(float _delta)
{
if (put your check here as you desire)
{
_animatedSprite.Play("DetachThisPart");
}
else
{
_animatedSprite.Stop();
}
}
}
Isn’t this C#? I got a little confused when I saw C++ in the title.
Juxxec | 2022-12-02 10:15
Firstly, thanks for your answer.
I dont’’t’ have a KinematicBody.
I made a Rocket as a « Spatial » in Godot.
I attach 3 « MeshInstance » to this spatial to have
different part of my rocket.
I attach an « AnimationPlayer » to this MeshInstance.
Then in my code in C++ (i’ m not using script in Godot)
i want to play the animation.
Thanks for your answer.
But I have a problem.
I made a Rocket as a « Spatial » in Godot.
I attach 3 « MeshInstance » to this spatial to have
different part of my rocket.
I attach an « AnimationPlayer » to this MeshInstance.
Then in my code in C++ (i’ m not using script in Godot)
i want to play the animation but what you write give me :
« get_node was not declared in this scope »
« AnimationPlayer is not a member of godot »
« Request for member ‘play’ in ‘(« AnimationPlayer »)’, which is of non-class type ‘const char[16]’