当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - Telling the scene manager you are ready to switch scenes?

问题描述:

Right now for my game, I have a scene manager and it runs a scene. What it does is send event messages to the scene such as render, input, etc. This has allowed me to make the scene unaware of the scene manager. I would now like the scene to be able to send the scene manager a message saying which scene it would like to switch to (in plain text). How could I do this without making the scene aware of the scene manager class?

Thanks

网友答案:

One way is to have the scene manager pass in NOT a reference to itself, but a reference to a smaller object that only supports the small number of methods needed for the particular messages to pass.

This could be an abstract class (aka "interface") which the scene manager implements, or a separate object.

And if you're using reference counting or smart pointers, consider making it a weak back-reference...

网友答案:

Consider the Observer Pattern: your scene will provide an interface for observers to be notified of interesting events. The scene manager could be one such observer that is interested in "request scene change" events. The scene would then send a notification to all observers when it is ready to do the swap.

分享给朋友:
您可能感兴趣的文章:
随机阅读: