I would like to have Sprite above UIView in the Cocos2d-x hierarchy.

Asked 1 months ago, Updated 1 months ago, 2 views

I had the opportunity to use Objective-C's UIView in Cocos 2d-x 3.2, but all UIViews are located before Sprite.
All views referred to by Objective-C, as well as UIView, are hierarchically located in front of the Cocos2d-x view.
When calling the addChild method, increasing the ZOrder value resulted in the same result.
Is it possible to place Sprite above UIView in the hierarchy?
Please let me know if you know more.

// Place UIView
UIView* view = [[UIView alloc] initWithFrame: CGRectMake(0,0,200,200)];
[ view setBackgroundColor: [UIColor blueColor];
UIView*rootView=(UIView*) cocos2d::Director::getInstance()->getOpenGLView()->getEAGLView();
rootView addSubview:view;

// Place Sprite
sprite->setPosition (Point (430,320));
this ->addChild(sprite,100,100);

Enter a description of the image here

ios objective-c cocos2d-x

2022-09-30 11:55

2 Answers

The cocos2d-x sprite is not added as View, but uses OpenGL. Directly drawn in a specific View (rootView in your code).
Therefore, I think it is not possible to display it above the UIView attached to the rootView.

2022-09-30 11:55

If you want to make sure you prioritize it, add the normal view to underView as shown in the picture below.

|                  |
|  +- [underView] -----+
|  |                 |
|  | + - [EAGLView] ----- +
+--|  |                |
   |  |                |
   +--|                |
      |                |

Rough code.

CGRect frame= (full screen?);
// Root view
UIView*rootView=[[UIView alloc] initWithFrame:frame];
// Low prio view
UIView* underView = [[UIView alloc] initWithFrame: frame ];
// EAGLView
UIView* EAGLView= (omitted);
// Add subview
rootView addSubview:underView;
rootView addSubview:EAGLView;

// The blue one
UIView* view = [[UIView alloc] initWithFrame: CGRectMake(0,0,200,200)];
[ view setBackgroundColor: [UIColor blueColor];
underView addSubview:view;

The background color of rootView and underView should be black instead of transparent. (Speedwise)

[Additional note]
Normally, you don't generate rootViews, but you use ViewController views.
I don't know how it's configured this time, so I can't say anything.

2022-09-30 11:55

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.