How to use multiple cameras in a 2d game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LucinaMan

I have a camera that is attached to my player, and follows it around. However, when I enter a room, I want the camera to be centered in the room, as it looks extremely weird if it still follows the player. How do I do this?

:bust_in_silhouette: Reply From: kidscancode

You can have any number of cameras in a scene, but only one can be “active”. This is done via the Camera2D’s current property.

Place a second camera in the room, then when the player enters, make the room’s camera current and the player’s will be deactivated. When they leave the room, do the opposite. For example, if you have an Area2D defining the room, you can do this using its collision signals:

func _on_Room_body_entered(body):
    if == "Player":
        $Camera2D.current = true

func _on_Room_body_exited(body):
    if == "Player":
        body.get_node("Camera2D").current = true

The room itself is a seperate scene, is it possible to just use the scene in code instead of an Area2D?

LucinaMan | 2018-07-21 22:47

Sure - either way, just disable the player’s camera and enable the one attached to the room.

kidscancode | 2018-07-21 22:56