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 9173691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:37:41+00:00 2026-06-17T16:37:41+00:00

I am wanting to create a base class that inherits from CCLayer . My

  • 0

I am wanting to create a base class that inherits from CCLayer. My reason is because I have a single-image, full screen CCSprite that I want to overlay on every scene of my application. Creating a base class, and adding a CCSprite containing the image as the top-most Z object seems to make sense because it will prevent me from having to re-code the same overlay implementation again and again for each scene.

I’ve been able to derive a class from CCLayer with relative ease. However, I cannot figure out how to correctly create a scene another layer class that is a child, of a child of CCLayer. How can this be done, and work?

I understand that when most users ask such questions, the first follow is “Show us your code.” I can show you the code but I am most interested in is a very generic implementation of Cocos2d object, that is derived from CClayer and can be used as a base class for other layers, pre-wiring common sprites and objects.

  • 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-06-17T16:37:41+00:00Added an answer on June 17, 2026 at 4:37 pm

    I think this may be your problem:

    “I cannot figure out how to create a scene that is a child, of a child of CCLayer.“

    As I understand it, Cocos layers are added as children to Cocos scenes, not the other way around, as the quote seems to imply.

    I think you could simply make a custom layer class, deriving it from CCLayer and adding your CCSprite. Then simply go to everywhere you are creating or deriving a CCLayer and instead create or derive it from your custom layer class and then show or hide the sprite when needed.

    Alternatively, and probably more easily, you could create a category on CCLayer adding a “showFullscreenSprite” method which simply creates the sprite and sets its image, then calls

    [self addChild:yourSprite z:yourSprite.zOrder tag:9999];
    

    You would also need a corresponding “hideFullscreenSprite” method which would simply do this

    [self removeChildByTag:9999 cleanup:YES];
    

    The nice thing about this approach is you wouldn’t need to sub-class at all and all of your CCLayers would now have your “showFullscreenSprite” and “hideFullscreenSprite” methods available.

    (Note: “9999” has to be some number you’re not already using as a CCNode tag. Make it big enough so you don’t have to worry about it. Maybe pull it out into a constant such as “FULL_SCREEN_SPRITE_TAG” or some such for readability.)

    Hope this helps!

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

Sidebar

Related Questions

Hi I am wanting to create a base class to inherit from but I
I have a hierarchy of classes that all derive from a base type and
I am wanting to create a VB.Net app that checks a database and then
So I have 2 tables, invoices and invoiceitems. I am wanting to create a
What I am wanting to do is create a PDF ideally from HTML code.
I'm an amateur programmer wanting to scrape data from a site that is similar
Basically I'm wanting to create a GPS system for my car that works offline,
I am wanting to create a Model that has a property of Service which
I'm wanting to create a program that you can import an mp3 file into,
I'm wanting to create a batch file that will back up my computer. This

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.