Anks
Anks

Reputation: 225

how to create transparent ccscene in cocos2d?

I need to show ccscene on game pause. But it should be transparent. Can anyone please help me with this??

Thank you,

Anks

Upvotes: 4

Views: 3851

Answers (2)

PingPongRhino
PingPongRhino

Reputation: 31

I know you already have an answer, but wanted to share my solution because I hit this link when researching the same issue. I also posted this in the cocos2d forums.

- (void)pauseSchedulerAndActionsRecursive:(CCNode *)node {
    [node pauseSchedulerAndActions];
    for (CCNode *child in [node children]) {
        [self pauseSchedulerAndActionsRecursive:child];
    }
}

- (void)resumeSchedulerAndActionsRecursive:(CCNode *)node {
    [node resumeSchedulerAndActions];
    for (CCNode *child in [node children]) {
        [self resumeSchedulerAndActionsRecursive:child];
    }
}

I have one scene and two layers, a stage/gameplay layer and a menu layer. My menus animate in and out, and I wanted my pause menu to be able to animate in and out as well. So I just added the above functions to my stage/gameplay layer. Then when the user hits pause, I call pauseSchedulerAndActionsRecursive: on my stage/gameplay layer and add my menu layer to the scene on top. My menu swallows all the touches, so touching is also disabled on the stage/gameplay layer while the menu layer is up. Then just call resumeSchedulerAndActionsRecursive: method to resume. Hope this helps someone out.

Upvotes: 2

Nitish
Nitish

Reputation: 14123

I suggest you should not create a separate scene for pause layer. What you can do is, create a layer similar to HUD Layer.
Second option would be going for something like this.Just dont set the background color of the layer.
Hope that helps.

Upvotes: 4

Related Questions