Hi,
I'd like to implement a dedicated scene that represents a door. If the character passes the door the camera should automatically move to the next room. Additionally, the door should have a state like "closed" and "open" and there are buttons (and probably keys) that open a door when you press (or use) it.
I am not sure how to implement a convenient scene that fulfills those requirements without technical debts.
I have an idea on how to structure the nodes
A scene tree that represents the door could look like this
Door (Node2D) ---
|
--- Sprite
|
--- Area2D
|
--- AnimationPlayer
The Sprite defines the appearance of the door, the Area2D triggers the walk through the door animation (camera moves to the next room) as soon as the player enters it. The door node has a script that handles everything
The AnimationPlayer contains an animation for opening the door.
Now the Node can be used in a DungeonScene in the following way
Dungeon ---
|
--- Player
|
--- Door ---
| --- Button
|
--- ...
The Door expects some children. For instance, if there is a button (that can be checked in the door's script) the door knows that it is a door that needs to be opened by a Button and if the Button is pressed by the player it opens up. If there is a key the door knows that it only opens up if the player owns that key. If there is no child the door knows that it is an open door.
Pro:
convenient to use. You only have to add the doors to your scenes and connect them with buttons, keys (and probably more) just by adding them as children
Contra:
Technical debt? The door scene relies on context information. I am not sure if this is considered an Anti-Pattern.
Is that a viable path or do you have other recommendations?
Thanks