Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7086197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:31:11+00:00 2026-05-28T07:31:11+00:00

Is it possible to detect which CCScene is currently showing on the scene? I

  • 0

Is it possible to detect which CCScene is currently showing on the scene? I have 2 CCScenes in my game and I want a certain action to occur if one is showing.

Also quick related question, if I wanted to check if a CCMenu is not showing currently would I do something like

    if (!menu) { 
    //Menu is not showing currently
    }

I am a bit of a noob when it comes to Cocos2D so please forgive me 🙂

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:31:11+00:00Added an answer on May 28, 2026 at 7:31 am

    You can use the CCDirector to tell which scene is running.

    [[CCDirector sharedDirector] runningScene];
    

    As for whether the menu is showing. You would have to check with the parent of the menu. If the parent where your CCLayer, then you could check by

    // assume menu is set up to have tag kMenuTag
    CCMenu * menu = [self getChildByTag:kMenuTag];
    

    If the menu is child of some other node, you can get the parent through a similar method and get a reference to the menu.

    If the menu == nil, it is not showing.

    UPDATE

    In cocos2d, you are discouraged from keeping references to all of your sprites, instead you should be giving each node a unique tag and use that to reference it. To achieve your first goal, you can give your scene a tag in your 2 respective CCLayer classes.

    You can set up your unique tags in an enum in a file called Tags.h, then import that into any classes that need access to your tags

    Example Tags.h

    enum {  
        kScene1Tag = 0,  
        kScene2Tag = 1,  
        kMenuTag = 2};
    

    Then in your layer class

    +(id) scene
    {
        // 'scene' is an autorelease object.
        CCScene *scene = [CCScene node];
        scene.tag = kScene1Tag;
        // 'layer' is an autorelease object.
        HelloWorld *layer = [HelloWorld node];
    
        // add layer as a child to scene
        [scene addChild: layer];
    
        // return the scene
        return scene;
    }
    

    Now when you grab the current scene you can check against the tags

    int currentSceneTag = [[CCDirector sharedDirector] runningScene].tag;
    if (currentSceneTag == kScene1Tag) {
    
    } else if (currentSceneTag == kScene2Tag) {
    
    }
    

    The tag property is from CCNode which is the base class of CCLayer, CCScene, CCSprite, CCMenu…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know if it's possible to have the script detect the URL
I want to know if it's possible to detect available colors in terminal which
Possible Duplicate: How to detect which row [ tr ] is clicked? I have
Possible Duplicate: Detect multitouch with Ontouch listener Android I have a question about detecting
Possible Duplicate: Detect Facebook page fan on the website I have a question to
Is it possible to detect if the visible map display more than one time
Is it possible to detect GSM mobile (any kind) which connected through serial port
Is it possible to detect which Photoshop version a brush set (.abr) file is
Is there any way to detect which keys are currently pressed using Tkinter? I
Is it possible to detect which proxy is active which is dead? using c#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.