CocosSharp icon indicating copy to clipboard operation
CocosSharp copied to clipboard

Consider making the CCScene the class that is subclassed by the template rather than CCLayer

Open vchelaru opened this issue 10 years ago • 4 comments

I find it awkward that the CocosSharp template includes a GameLayer.cs file which inherits from Layer. This seems to imply that the user should be using this to contain their top-level game-mode logic.

I propose instead to have a GameScene rather than GameLayer as part of the template, and to encourage the pattern of having CCScene serve as the base class.

Any non-trivial game will include scenes with multiple layers. In such a game it makes sense for game logic to be either in the scene itself, or for each layer to handle its own logic, but to be contained within one scene.

This is especially important as there may be logic that needs to be performed in the context of all layers. As is currently implemented a game with multiple layers must instantiate the other layers within the GameLayer and add them to the scene, which requires that the layer has knowledge of the scene rather than a "one way" relationship between scenes and layers.

vchelaru avatar Feb 21 '15 19:02 vchelaru

@kjpou1 Asked that I create a sample project to show what I mean, will create and upload soon.

vchelaru avatar Feb 21 '15 20:02 vchelaru

I spoke with @kjpou1 and he asked for examples.

Here's an example project that replaces the GameLayer with a GameScene:

https://dl.dropboxusercontent.com/u/21777714/GameWithSceneAsBase.zip

Also, in case it helps, I'll present a conceptual example using a game I'm working on:

This scene shows a situation where at least two distinct layers exist - the "world" layer with the environment/characters, and the UI in the foreground. Although they're not visible we also have a "text" layer for displaying dialog, a "tutorial" layer for tutorial arrows, a "popup" layer, and a "pausemenu" layer. Non-trivial games will often have a more complicated setup with multiple layers, and in this case which layer gets the "honor" of holding all of the game logic? It seems like the game logic should probably be held at the root, which would be a class that inherits from Scene, and then the individual layers would be contained in this master Scene-deriving class.

It's also worth noting that the game logic may need information from one Layer to apply to another, and this cross-layer logic shouldn't belong in any one layer.

vchelaru avatar Mar 05 '15 23:03 vchelaru

I totally agree !. Just started with games and templates supplied are not logical for for should happen. Plus looking for new templates for v1.7 that includes stepping through various different scenes. About to go look at your example. Keep up the good work Thanks

scubapk avatar Dec 11 '15 03:12 scubapk

Yes, after working on a few samples, I've come around to agree with @vchelaru . We're in the process of updating our samples to incorporate CocosSharp v1.7.0.0-pre1's new setup and are setting up our samples in this suggested fashion. For example, check out the new GoneBananasForms sample here.

rtabbara avatar Dec 12 '15 10:12 rtabbara