0 votes

In my game, I want to the player to be able to interact with objects and have a dialogue box pop up with character portraits and stuff. I also want to be able to apply a shaking effect to the dialogue box. The dialogue box is on a separate canvas layer than the player. I tried applying a shaking effect to the Camera2D under the player node, but that just shook the player and the background instead of the stuff in the CanvasLayer. I tried adding a Camera2D as a child of the dialogue box, but when I made it current, the camera was pointed at the origin, so it didn't align with the player's current position.

How do I apply a shaking effect to the dialogue box while still showing the player's current position in the background?

in Engine by (7,190 points)

1 Answer

0 votes
Best answer

Just use an AnimationPlayer or Tween to change either the offset-property of the whole CanvasLayer or the position-/rect_position-property of your dialogue box. Here's an code example for using a Tween to shake the CanvasLayer:

extends Node2D

var tween_values = [0.0, 20.0]

func _enter_tree():
    var tween = Tween.new()
    tween.name = "Tween"
    tween.connect("tween_completed", self, "on_tween_completed")

func _ready():

func start_tween():
    $Tween.interpolate_property($CanvasLayer, "offset:y", tween_values[0], tween_values[1], 1.0)

func on_tween_completed(object, key):
by (10,315 points)
selected by

Thanks, using an AnimationPlayer worked.

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.