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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:06:59+00:00 2026-06-08T10:06:59+00:00

I have a class GameScene, during init of which I make a scene and

  • 0

I have a class GameScene, during init of which I make a scene and attach a child to it – a layer. I noticed strange code for it:

    CCScene *scene = [CCScene node];
    CCLayer *layer = [GameScene node];
    [scene addChild:layer];

Why not do this instead?

CCLayer *layer = [CCLayer node];

This doesn’t add to readability or am I missing something fundamental here? Also, why not use alloc init at all?

  • 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-08T10:07:00+00:00Added an answer on June 8, 2026 at 10:07 am
    [CCNode node];
    

    is a static (class) method. It automatically calls [[[self alloc] init] autorelease];

    Any CCNode subclass can be initialized using this static initializer. It is basically for convenience and is really not needed. (Although, like I said, it is nice to have).

    Class methods use the “+” sign and instance methods use the “-” sign. Class methods are like static methods in Java. They can be called without creating an instance of that class.
    It could look like this: [YourClass doSomething]; //Doesn't need an instance of YourClass

    Instance methods need an instance of their class to be able to be run. This would look like:

    YourClass *yClass = [[YourClass alloc] init];
    [yClass doSomethingElse]; //Needs an instance of YourClass
    

    I haven’t looked, but I assume the node method looks something like this:

    + (CCNode*)node {
        return [[[self alloc] init] autorelease];
    }
    

    The odd declaration just returns a scene (initialized with a static initializer) with your custom layer as a child, that the CCDirector can then use and display.

    EDIT: something I feel would add clarity.

    The strange declaration is just a static initializer + (CCScene*)scene which returns a scene.

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

Sidebar

Related Questions

I have a class called GameScene, with is a subclass of a cocos2d Scene.
I have Class and Student objects. Both have collection of another as property. Which
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a
We have class lua. In lua class there is a method registerFunc() which is
I have class like this below shown. which contains the shopping items where the
I have class which implements Countable, ArrayAccess, Iterator and Serializable. I have a public
How to do you make Gesture Recognizers only accessible from one scene? I have
I have three classes which I have a problem with. They are named: GameScene,
I have class Building in which i have one class member NSMutableArray *subnode.I have
I have a GameScene where I add a large image as child. I want

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.