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();
}
/**
@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();
}
相关文章推荐
- Cocos2d-x简单Box2d代码示例|点击碰撞>HelloWorldScene.cpp<代码演示>
- Cocos2d-x简单Box2d代码示例|点击碰撞>HelloWorldScene.h<代码演示>
- cocos2d-x简单动画:处理Texture2D和plist文件处理动画<代码演示>
- Cocos2d-x简单游戏<植物大战僵尸>代码实现|第九部分:游戏场景GameScene.cpp<后续会提供源码下载链接>
- Cocos2d-x简单游戏<植物大战僵尸>代码实现|第二部分:菜单场景<后续会提供源码下载链接>
- Cocos2d-x使用Javascript开发js绑定C++<代码示例>
- Cocos2d-x简单游戏<捕鱼达人>代码实现|第二部分:子弹、渔网、大炮类
- (原创)cocos2d-x 3.0 示例代码分析1:AppDelegate
- Cocos2d-x简单游戏<植物大战僵尸>代码实现|第三部分:通关场景<后续会提供源码下载链接>
- Cocos2d-x简单游戏<植物大战僵尸>代码实现|第六部分:植物类<后续会提供源码下载链接>
- OC中KVC设计模式简单实用<代码演示>
- Cocos2d-x简单游戏<捕鱼达人>代码实现|第四部分:加载场景类
- Cocos2d-x简单游戏<植物大战僵尸>代码实现|第四部分:通关失败场景<后续会提供源码下载链接>
- Cocos2d-x简单游戏<植物大战僵尸>代码实现|第七部分:僵尸类<后续会提供源码下载链接>
- Cocos2d-x简单游戏<捕鱼达人>代码实现|第三部分:菜单类
- <cocos2d-x for wp7>使用box2d来做碰撞检测(且仅用来做碰撞检测)
- Cocos2d-x控件使用CCControlSlider<代码演示>
- Cocos2d-x控件使用CCControlSwitch<代码演示>
- Cocos2d-x简单游戏<捕鱼达人>代码实现|第五部分:游戏类
- Cocos2d-x简单游戏<植物大战僵尸>代码实现|第八部分:子弹类<后续会提供源码下载链接>