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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:56:40+00:00 2026-05-27T18:56:40+00:00

I made an App using cocos2D that has a hierarchical structure. And I used

  • 0

I made an App using cocos2D that has a hierarchical structure.

And I used a UIButton on glView in a child layer.

When I get back to parent layer, the button still on it’s position.

I want to terminate that.

How can I do this?

Here’s the code.

MainHallLayer.m

- (id)init
{
    self = [super init];

    if (self != nil)
    {
        CCMenu *menuLists = [CCMenu menuWithItems: nil];
        menuLists.position = ccp(screenSize.width/2, screenSize.height/2);
        [self addChild:menuLists z:10];

        NSString *fontName = [NSString stringWithFormat:@"Chalkboard SE"];
        CGFloat fontSize = 28;

        {
            CCLabelTTF *label = [CCLabelTTF labelWithString:@"Touch Field : Getting 
                            touches coordinates" fontName:fontName fontSize:fontSize];
            [label setColor:ccc3(0.0, 0.0, 0.0)];
            label.anchorPoint = ccp(0, 0.5f);
            CCMenuItem *menuItem = [CCMenuItemLabel itemWithLabel:label block:^(id 
                                                                            sender)
            {
                CCScene *scene = [TouchField1Layer node];
                [ReturningNode returnToNodeWithParent:scene];
                [[CCDirector sharedDirector] replaceScene:scene];
            }];
            [menuLists addChild:menuItem];
        }
    }
    return self;
}

ReturnToNode.m
– (id)initWithParentNode:(CCNode *)parentNode
{
self = [super init];

    if (self != nil) 
    {
        CGSize screenSize = [[CCDirector sharedDirector]winSize];

        CCLabelTTF *label = [CCLabelTTF labelWithString:@"  <= Return" 
                                               fontName:@"Gill Sans" 
                                               fontSize:30.0f];
        label.color = ccMAGENTA;

        id tint_1 = [CCTintTo actionWithDuration:0.333f red:1.0 green:.0f blue:.0f];
        id tint_2 = [CCTintTo actionWithDuration:0.333f red:.5f green:.5f blue:.0f];
        id tint_3 = [CCTintTo actionWithDuration:0.333f red:.0f green:1.0 blue:.0f];
        id tint_4 = [CCTintTo actionWithDuration:0.333f red:.0f green:.5f blue:.5f];
        id tint_5 = [CCTintTo actionWithDuration:0.333f red:.0f green:.0f blue:1.0];
        id tint_6 = [CCTintTo actionWithDuration:0.333f red:.5f green:.0f blue:.5f];

        id sequence = [CCSequence actions:tint_1,tint_2,tint_3,tint_4,tint_5,tint_6, nil];
        id repeatAction = [CCRepeatForever actionWithAction:sequence];
        [label runAction:repeatAction];

        CCLayerColor *labelBackground = [CCLayerColor layerWithColor:ccc4(0.0, 0.0, 70, 40) width:label.contentSize.width + 20 height:label.contentSize.height + 20];

        [label addChild:labelBackground z:-1];

        CCMenuItem *menuItem = [CCMenuItemLabel itemWithLabel:label block:^(id sender)
        {
            [self removeFromParentAndCleanup:YES];
            [[CCDirector sharedDirector] replaceScene:[TouchControllerLayer scene]];
        }];

        CCMenu *menu = [CCMenu menuWithItems:menuItem, nil];
        [menu alignItemsVertically];
        menu.position = CGPointMake(label.contentSize.width/2 , screenSize.height - 20);
        [self addChild:menu];

        [parentNode addChild:self z:1000];
    }
    return self;
}

+ (id)returnToNodeWithParent:(CCNode *)parentNode
{
    return [[[self alloc] initWithParentNode:parentNode] autorelease];
}

TouchField1Layer.m
– (id)init
{
self = [super init];

    if (self != nil) 
    {
        BackgroundLayer *background = [BackgroundLayer node];
        TouchField3Layer *layer = [TouchField3Layer node];

        [self addChild:background z:3];
        [self addChild:layer z:2];

        [self preparingTools];
    }
    return self;
}

- (void)preparingTools
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(0, 0, 100, 40);

    UIView *glView = [CCDirector sharedDirector].openGLView;
    glView.tag = TAG_GLVIEW;
    [glView addSubview:button];
}

Any advices, helps are welcome. Always thanks. Bless You.

  • 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-27T18:56:41+00:00Added an answer on May 27, 2026 at 6:56 pm

    If you add UIKit views you will have to remove them manually at the appropriate point in time. Cocos2D does not manage the lifetime of UIKit views, only classes derived from CCNode.

    For example when changing scenes you will have to remove the UIButton from the glView either in -(void) dealloc or in -(void) cleanup.

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

Sidebar

Related Questions

I have a web app, that also has an iPhone and Android app using
I made a quiz app using wordpress using a quiz plugin so that, the
I've made an app init function that I'm using both in Java and GWT
I've made a small web app using web.py that I now want to put
I have made an app that gets an array of addresses from a web
I am trying to get a web app made on Zend Framework up but
Greets, Made some app on android. I for the life of me can't get
In the Java Swing app I made it seems to me that all the
Made a simple app which using a timer, counts the number of mouse clicks
I create an .app using py2app, and the GUI was made with pyqt4, and

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.