I'm attempting to make my first cocos2d (for iphone) multiplayer game and having difficulty understanding how to interact with a scene once it is running.

The game is a simple turn-based one and so I have a GameController class which co-ordinates the rounds. I also have a GameScene class which is the actual scene that is displayed during a round of the game. The basic interaction I need is for the GameController to be able to pass messages to the GameScene class.. such as StartRound/StopRound etc.

The thing that complicates this is that I am loading the GameScene with a LoadingScene class which simply initialises the scene and replaces the current scene with this one, so there is no reference from GameController to GameScene, so passing messages is quite tricky.

Does anyone have any ways to get around this, ideally I would still like to use a Loading class as it smooths out the memory hit when replacing scenes.


1 Answer 1


Solution on my first try was... Have a getInstance() static method in GameScene class

     +(GameScene*) getInstance()
        return s_currentInstace;//This is the static variable that holds the current GameScene

you should update 's_currentInstace' variable as and when you create and destroy GameScene accordingly.(i mean set s_currentInstace to 'nil' when GameScene is getting destroyed)

When you want to send a message to GameScene, you just need to call getInstance() on GameScene and based on the return value you act ;).

Will update this when i have some more solutions.

  • \$\begingroup\$ Thankyou, this is certainly one possible way. I did eventually get it working by using [[CCDirector sharedDirector]runningScene] from here and casting that to my GameScene, although your way may be better. \$\endgroup\$
    – cjroebuck
    Commented Feb 16, 2011 at 8:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .