您的位置:首页 > 移动开发 > Cocos引擎

Cocos2d-x简单Box2d代码示例|点击碰撞>AppDelegate.h及AppDelegate.cpp<代码演示>

2014-03-19 15:52 701 查看
#include "cocos2d.h"

/**

@brief    The cocos2d Application.

The reason for implement as private inheritance is to hide some interface call by CCDirector.

*/

class  AppDelegate :private
cocos2d::CCApplication
{

public:
    AppDelegate();
   virtual ~AppDelegate();

   /**

    @brief    Implement CCDirector and CCScene init code here.

    @return true    Initialize success, app continue.

    @return false   Initialize failed, app terminate.

    */
   virtual
bool applicationDidFinishLaunching();

   /**

    @brief  The function be called when the application enter background

    @param  the pointer of the application

    */
   virtual
void applicationDidEnterBackground();

   /**

    @brief  The function be called when the application enter foreground

    @param  the pointer of the application

    */
   virtual
void applicationWillEnterForeground();
};

#endif // _APP_DELEGATE_H_

#include "AppDelegate.h"

#include "HelloWorldScene.h"

#include "SimpleAudioEngine.h"

USING_NS_CC;

using namespace
CocosDenshion;

AppDelegate::AppDelegate() {

}

AppDelegate::~AppDelegate() 
{
}

boolAppDelegate::applicationDidFinishLaunching() {

    // initialize director
   CCDirector* pDirector =
CCDirector::sharedDirector();
   CCEGLView* pEGLView =
CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);

    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 /60);

    // create a scene. it's an autorelease object
   CCScene *pScene =
HelloWorld::scene();

    // run
    pDirector->runWithScene(pScene);

    return
true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
voidAppDelegate::applicationDidEnterBackground() {

    

    CCDirector::sharedDirector()->stopAnimation();

    

    SimpleAudioEngine::sharedEngine()->pauseAllEffects();

    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
voidAppDelegate::applicationWillEnterForeground() {

    

    CCDirector::sharedDirector()->startAnimation();

    

    SimpleAudioEngine::sharedEngine()->resumeAllEffects();

    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();

    
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐