Game Development Reference
In-Depth Information
Who begets whom?
If have you never worked with either Cocos2d or Cocos2d-x before, the way the initial
scene()
method is instantiated may lead to dizziness. To recap, in
AppDelegate
you
have:
auto scene = HelloWorld::createScene();
director->runWithScene(scene);
Director
needs a
Scene
object to run, which you can think of as being your applica-
tion, basically.
Scene
needs something to show, and in this case, a
Layer
object will do.
Scene
is then said to contain a
Layer
object.
Here a
Scene
object is created through a static method
scene
inside a
Layer
derived
class. So the layer creates the scene, and the scene immediately adds the layer to itself.
Huh? Relax. This incestuous-like instantiation will most likely happen only once, and you
get nothing to do with it when it happens. So you can easily ignore all these funny goings-
on and look the other way. I promise instantiations will be a much easier task after this first
one.