0

I have a UITableView that shows scores and names. I also have animated objects that move around the screen.. However they go under the tableview and not visible no matter what z-index value that have.. How can I make the animated objects go on top of my UITableView? Thanks..

user123
  • 2,711
  • 5
  • 21
  • 25

2 Answers2

1

Before you continue (samfisher's solution works to place all UIKit below cocos2d views) keep this in mind:

It is technically impossible to have a UIKit view in cocos2d where cocos2d draws nodes both in front of and behind the UIKit view at the same time.

In other words: a UIKit view can either be completely in front of all cocos2d nodes, or completely behind all of cocos2d nodes.

The reason is that cocos2d is a view from UIKit's perspective.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
0

you must have added UITableView as subview of CCDirector's openGLView.

All the COCOS2D animations with the objects are going on the openGLView which is obviously below the TableView so z index wont work in this case.

All you have to do is insert the UITableView directly on UIWindow and move it below the openGLView. You can also use:

[<UIWindow> insertSubview:<TableView> belowSubview:<openGLView>];

all you need to do is to make your openGLView transparent and make sure that you have no background image added on CCLayer (or else it will cover the )

so the question is hoe to make your openGLView - transparent

-(void) initGLDefaultValues
{
    // This method SHOULD be called only after openGLView_ was initialized
    NSAssert( openGLView_, @"openGLView_ must be initialized");

    [self setAlphaBlending: YES];
    [self setDepthTest: YES];
    [self setProjection: CCDirectorProjectionDefault];

    // ***** NEW CODE: make open gl view transparent
    openGLView_.opaque = NO;
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    // disable regular, opaque clear color
    //glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        // ***** NEW CODE end
}
Saurabh Passolia
  • 8,099
  • 1
  • 26
  • 41