Complete Guide to Godot-DragonBones V2 Commands and How to Use Them


Here's the full commands of Godot-DragonBones V2. DragonBones is a powerful 2D skeletal animation tool, and when integrated with Godot, it provides developers with an efficient way to create and control 2D animations in their games. By understanding the key commands, you can have full control over your animations, events, audio synchronization, and more.

1. Basic Commands of Godot-DragonBones

1.1 play(animation_name: String)

Description: This command is used to play a specific animation by its name.

Example:

dragonbones.play("idle")

This will play the "idle" animation.

1.2 stop()

Description: Stops the current animation.

Example:

dragonbones.stop()

This will stop any ongoing animation.

1.3 pause()

Description: Pauses the current animation.

Example:

dragonbones.pause()

This will pause the current animation and can be resumed later.

1.4 animation_completed (Signal)

Description: A signal fired when the animation completes.

Example:


dragonbones.connect("animation_completed", self, "_on_animation_completed")

func _on_animation_completed(animation_name: String):
    print("Animation completed: ", animation_name)
    

This signal will be triggered when the animation finishes playing.

1.5 event_dispatched (Signal)

Description: A signal fired when an event is dispatched from the animation.

Example:


dragonbones.connect("event_dispatched", self, "_on_event_dispatched")

func _on_event_dispatched(event_name: String):
    print("Event dispatched: ", event_name)
    

Use this signal to capture specific events such as footsteps or attacks that are triggered in the animation timeline.

1.6 set_flip(horizontal: bool, vertical: bool)

Description: Flips the character horizontally and/or vertically based on the parameters.

Example:

dragonbones.set_flip(true, false)  # Flip horizontally

This can be useful for mirroring the character's movement direction.

1.7 is_playing()

Description: Checks if an animation is currently playing.

Example:


if dragonbones.is_playing():
    print("Animation is playing.")
    

This helps you verify if an animation is still running.

2. How to Add Events in DragonBones Editor

To add events to your animation, follow these steps:

  • Open the Timeline in DragonBones Editor.
  • Select the frame where you want to add the event.
  • Click on the Add Event button at the top of the Timeline.
  • Name the event (e.g., footstep or attack) and click OK.
  • Export your project as .ske and .json.

3. Triggering Audio Based on Animation

You can trigger sounds based on the current animation using AudioStreamPlayer2D. Here’s how:


if current_animation == "idle":
    audio_player.stream = preload("res://sounds/idle.wav")
elif current_animation == "move":
    audio_player.stream = preload("res://sounds/move.wav")
elif current_animation == "hurt":
    audio_player.stream = preload("res://sounds/hurt.wav")
audio_player.play()  # Play the sound

4. Conclusion

In this article, we've covered the essential commands and methods for controlling DragonBones animations in Godot. From playing and stopping animations to synchronizing them with sounds and events, these commands give you full control over your game’s animation system. By using these features, you can create dynamic, responsive, and engaging animations for your characters in Godot.

Sources

For more detailed information, visit the official resources:

Post a Comment

Previous Post Next Post

Contact Form