忍者ブログ
  • 2024.04
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 2024.06
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

【2024/05/06 03:55 】 |
Android+cocos2d-xで、画面が戻ってこない
アプリ内から動画広告を再生して、画面を閉じても
ゲーム画面が表示されなかった

printデバッグしてみると、cocos2d側のupdate系が呼ばれていない
つまり、cocos2d-xがresumeされていないようだ

Android側のコードを探してみると
Cocos2dxRenderer.javaの中に、
Androidからcocos2dxを呼び出しているらしきライフサイクル系のメソッド群があった

private static native void nativeTouchesBegin(final int id, final float x, final float y);
private static native void nativeTouchesEnd(final int id, final float x, final float y);
private static native void nativeTouchesMove(final int[] ids, final float[] xs, final float[] ys);
private static native void nativeTouchesCancel(final int[] ids, final float[] xs, final float[] ys);
private static native boolean nativeKeyDown(final int keyCode);
private static native void nativeRender();
private static native void nativeInit(final int width, final int height);
private static native void nativeOnSurfaceChanged(final int width, final int height);
private static native void nativeOnPause();
private static native void nativeOnResume();




さてnativeOnResumeは、

Cocos2dxRenderer::handleOnResume();
Cocos2dxGLSurfaceView::onResume();
Cocos2dxActivity::onResume();
MainActivity::onResume();


ちゃんと呼び出されている


というわけで、中の実装を見てみる

nativeOnResume()の実体は、

cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxRenderer.cpp
のファイル内に、それぞれの関数の実体が定義されていた



JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeOnResume() {
if (Director::getInstance()->getOpenGLView()) {
Application::getInstance()->applicationWillEnterForeground();
cocos2d::EventCustom foregroundEvent(EVENT_COME_TO_FOREGROUND);
cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&foregroundEvent);
}
}



このif文が真になっていなければ、説明がつく
というわけで、applicationWillEnterForeground()が実行されているかというと
ちゃんとされていた。

ということは、EventDispatchができていないのか

Scene::update()は、iOSの場合

HomeScene::update(float)
cocos2d::Scheduler::scheduleUpdate(cocos2d::Node*, int, bool)::'lambda'(float)::operator()(float) const
cocos2d::Scheduler::update(float)
cocos2d::Director::drawScene()
cocos2d::DisplayLinkDirector::mainLoop()
-[CCDirectorCaller doCaller:]


と言う順序で呼び出される

まだ不明
PR
【2016/08/07 15:14 】 | cocos2d-x | 有り難いご意見(0)
<<NDKデバッグはできないのか | ホーム | androidアプリをコードから終了させるとき>>
有り難いご意見
貴重なご意見の投稿














<<前ページ | ホーム | 次ページ>>