0 votes

I want to put a timer that starts working at the first level and only stops at the last, and that in the exchange of scenes your values ​​are carried forward.
For example, if level 1 is over in 3 minutes, level 2 starts with the timer setting 3 minutes, and so on.

The best way is to do this with Singleton? If yes, how? I can not think of a very simple logic.

Tks guys

in Engine by (174 points)

1 Answer

+1 vote
Best answer

I'd recommend create a bigger scene called Game or something containing your level scenes and your timer.
Trust me, the timer is not the only thing you need between scenes (e.g. UI, music).
You probably want to test run a single scene with F6 at some point, that's when singletons come bite back at you.

This is my scene tree for my games, been working pretty well, keeping singletons to a minimum:

 ┖╴Game
    ┠╴Mechanics 
    ┃  ┠╴PlayerControl
    ┃  ┠╴LevelTimer # here's your timer
    ┃  ┖╴Scoring
    ┠╴World
    ┃  ┠╴Ground
    ┃  ┠╴Walls # swap this out for another and you got a new level
    ┃  ┖╴Player
    ┖╴UI
       ┠╴FPS
       ┠╴TimeLabel # display your Timer.time_left
       ┖╴Pause
by (4,221 points)
selected by

This looks incredible; but is not it a bad way to consume the memory of the PC?
Do a lot of scenes put together in the same file do not work too much in execution?

Could you please print your scene scheme, I'm having a bit of trouble figuring it out in Godot itself; I've always worked with separate nodes interacting via call them by code or singleton

Scene files are just text files so it doesn't really add up to their sizes.
By scene scheme, you mean how the nodes interact with each other (accessing data, sending signals)?

By scene scheme I was referring to what nodes you use to make this unified mount. for example, by the "Game" scene I imagine you do with a Node; for "World" scene I imagine it to be a Node2D or 3D, depending on the game. Now for "Mechanics" scene I can not imagine which Node would be used; The same goes for UI ... a Control Node?

I do not know if I'm being clear, but when I think of my separate scenes they have an end in them. For example, a "Player" scene would start with a KninematiBody, which would then go to a Node2D of the Level in question.
Now, if I had to subordinate these two to a superior "World" or "Game" scene, or even a "Player Control", what would be the possibilities? Work with a lot of generic Nodes or is there a more specific way?

In fact, your method seems to be much better than mine. But is that as I never did, I was left with these doubts

Game, Mechanics and World can be a Node2D or Spatial depending the type of game (2D or 3D), World can be a YSort in a 2D game.
Children of Mechanics are the same (Node2D or Spatial).
UI is a CanvasLayer so they're locked in place.

World children nodes' types depend on what you need:
- Player can be a KinematicBody or RigidBody
- Level can be many things from TileMap, GridMap, Node2D, YSort to Spatial.

Mechanics children nodes are invisible.
World children nodes are visible game entities.

Thanks Dlean Jeans, now make much more sense to me; I'll try your method.

Looks like much better than make a lot of singletons and loads.

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 Frequently asked questions and 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 [email protected] with your username.