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?

asked Mar 22 in Engine by exuin (41 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):
answered Mar 23 by njamster (8,986 points)
selected Mar 24 by exuin

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.