Cocos2d-x v3.3rc0 webView

Hello.

I’m currently experimenting with the webView and I wonder how to add an image over it so the user can press on it to go back to e.g. a menu. I tried to attach an image with a higher Z-index than the actual webView, but It doesn’t work… I cant see the image.

webView->....
this->addChild(webView, 0);

image->....
this->addChild(image, 1);

It’s a iOS & Android project by the way & the webView is fullscreen.

Kind regards,

My understanding is that native UI elements (web view and video view) are separate from the GL view Cocos is rendered in, thus the Z order does not matter. By default, they are on top of the GL view, which means they will catch all of the touch events that happen in their bounds; or if you make some changes to how the views are added (see Enhancement request for VideoPlayer) you can insert it behind the GL view, in which case the GL view will catch all the touches. For web views, I stick with the default, and leave a space at the top for a Cocos header with an exit button.

1 Like

Oh ok! I understand.

How would I do to reduce the height by 50px only of the webView then? I’m using the code below.

Size visibleSize = Director::getInstance()->getVisibleSize();
_webView->setContentSize(visibleSize);
auto visibleSize = Director::getInstance()->getVisibleSize();
auto origin = Director::getInstance()->getVisibleOrigin();

auto webview = WebView::create();
webview->setContentSize(visibleSize - Size(0,20));
webview->setAnchorPoint(Vec2::ZERO);
webview->setPosition(Vec2::ZERO);
webview->loadURL("http://www.baidu.com");
this->addChild(webview);
2 Likes

It looks like that the onShouldStartLoading callback doesn’t work on the Android Platform at all, tried with my code and with cpp-tests. On iOS it works fine.

Does anyone have a quick fix for this?

Bumping thread onShouldStartLoading doesn’t work on Android. Does anyone know how to fix this?

Kind regards,