AppDelegate.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "AppDelegate.h"
  2. #include "CCLuaEngine.h"
  3. #include "SimpleAudioEngine.h"
  4. #include "cocos2d.h"
  5. using namespace CocosDenshion;
  6. USING_NS_CC;
  7. using namespace std;
  8. AppDelegate::AppDelegate()
  9. {
  10. }
  11. AppDelegate::~AppDelegate()
  12. {
  13. SimpleAudioEngine::end();
  14. }
  15. // if you want a different context, modify the value of glContextAttrs
  16. // it will affect all platforms
  17. void AppDelegate::initGLContextAttrs()
  18. {
  19. // set OpenGL context attributes: red,green,blue,alpha,depth,stencil
  20. GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};
  21. GLView::setGLContextAttrs(glContextAttrs);
  22. }
  23. bool AppDelegate::applicationDidFinishLaunching()
  24. {
  25. // set default FPS
  26. Director::getInstance()->setAnimationInterval(1.0 / 60.0f);
  27. // Runtime end
  28. cocos2d::log("iShow!");
  29. return true;
  30. }
  31. // This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
  32. void AppDelegate::applicationDidEnterBackground()
  33. {
  34. Director::getInstance()->stopAnimation();
  35. SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
  36. }
  37. // this function will be called when the app is active again
  38. void AppDelegate::applicationWillEnterForeground()
  39. {
  40. Director::getInstance()->startAnimation();
  41. SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
  42. }