Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
    
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. –  cjroebuck Feb 16 '11 at 8:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.