AppDelegate.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /****************************************************************************
  2. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  3. http://www.cocos.com
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated engine source code (the "Software"), a limited,
  6. worldwide, royalty-free, non-assignable, revocable and non-exclusive license
  7. to use Cocos Creator solely to develop games on your target platforms. You shall
  8. not use Cocos Creator software for developing other software or tools that's
  9. used for developing games. You are not granted to publish, distribute,
  10. sublicense, and/or sell copies of Cocos Creator.
  11. The software or tools in this License Agreement are licensed, not sold.
  12. Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #include "AppDelegate.h"
  22. #include "cocos2d.h"
  23. #include "cocos/scripting/js-bindings/manual/jsb_module_register.hpp"
  24. #include "cocos/scripting/js-bindings/manual/jsb_global.h"
  25. #include "cocos/scripting/js-bindings/jswrapper/SeApi.h"
  26. #include "cocos/scripting/js-bindings/event/EventDispatcher.h"
  27. #include "cocos/scripting/js-bindings/manual/jsb_classtype.hpp"
  28. USING_NS_CC;
  29. AppDelegate::AppDelegate(int width, int height) : Application("Cocos Game", width, height)
  30. {
  31. }
  32. AppDelegate::~AppDelegate()
  33. {
  34. }
  35. bool AppDelegate::applicationDidFinishLaunching()
  36. {
  37. se::ScriptEngine *se = se::ScriptEngine::getInstance();
  38. jsb_set_xxtea_key("");
  39. jsb_init_file_operation_delegate();
  40. #if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
  41. // Enable debugger here
  42. jsb_enable_debugger("0.0.0.0", 6086, false);
  43. #endif
  44. se->setExceptionCallback([](const char *location, const char *message, const char *stack) {
  45. // Send exception information to server like Tencent Bugly.
  46. cocos2d::log("\nUncaught Exception:\n - location : %s\n - msg : %s\n - detail : \n %s\n", location, message, stack);
  47. });
  48. jsb_register_all_modules();
  49. se->start();
  50. se::AutoHandleScope hs;
  51. jsb_run_script("jsb-adapter/jsb-builtin.js");
  52. jsb_run_script("main.js");
  53. se->addAfterCleanupHook([]() {
  54. JSBClassType::destroy();
  55. });
  56. return true;
  57. }
  58. // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
  59. void AppDelegate::onPause()
  60. {
  61. EventDispatcher::dispatchOnPauseEvent();
  62. }
  63. // this function will be called when the app is active again
  64. void AppDelegate::onResume()
  65. {
  66. EventDispatcher::dispatchOnResumeEvent();
  67. }