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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:41:20+00:00 2026-05-29T14:41:20+00:00

I have a scene, a main layer and a child layer, the main layer

  • 0

I have a scene, a main layer and a child layer, the main layer contains a Player* object which is a subclass of CCSprite, I want to pass the Player into the child layer like so:

BattleLayer* b = [[BattleLayer alloc] initWithPlayer:_player];
[((CCScene*)self.parent) addChild:b];

-(id)initWithPlayer:(Player *)p
{
    if((self=[super init]))
    {
        _player = p;
        [self addChild:_player.spriteSheet];
    }
    return self;
}

However, this gives an error when I do [self addChild:_player.spriteSheet];

*** Assertion failure in -[BattleLayer addChild:z:tag:]

I’ve tried removing the sprite from the main layer before passing it in, but even with cleanup:NO this gives an error of

*** -[CCSpriteBatchNode tag]: message sent to deallocated instance 0x747a580

What am I doing wrong here? And what’s the best way of achieving this?

  • 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-29T14:41:21+00:00Added an answer on May 29, 2026 at 2:41 pm

    I’ve run in to this before and retained and then released after reordering. My objects were autoreleased and retained only by the CCLayer so this worked, Try:

    [_player retain];
    [_player removeFromParentAndCleanUp:YES];
    [self addChild:_player];
    [_player release];
    

    However I have run into a bug with rapid removal and re-adding of sprites and it is described here: http://www.cocos2d-iphone.org/forum/topic/9980

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

Sidebar

Related Questions

I have a menu scene hierarchy like so: Scene | Background Layer | |
I have a scene, called testScene, it works like this: @interface testScene : myScene
I have a scene and an object placed in some coordinates. I can transform
I have an opengl scene rendering on an EAGLView layer and some other elements
I have a program in which the user adds multiple objects to a scene.
I am rendering a scene in which I have two spheres. I am revolving
I have a simple solid modeling application in which I want to implement several
I have a level scene in my game in which I am selecting the
I have a parent scene node in my engine, and a child. child's transform(position,
I have one QGraphicsScene as the main scene with several movable QGraphicsItem s in

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.