axmol/Cocos2dSimpleGame/Cocos2dSimpleGameAppDelegat...

87 lines
2.3 KiB
C++
Raw Normal View History

// Application application cpp file.
// Original file name: cocosTemplateApp.cpp
// Generated by TOPS Builder:Project wizard,Date:2010-09-27
#include "Cocos2dSimpleGameAppDelegate.h"
#include "HelloWorldScene.h"
2010-10-12 16:14:34 +08:00
#include "Resource.h"
using namespace cocos2d;
2010-10-12 16:14:34 +08:00
extern const AppResourceEntry Cocos2dSimpleGameResourceEntry;
// the works are the same as NSObject<UIApplicationDelegate>::applicationDidFinishLaunching of cocos2d-iphone
bool AppDelegate::initCocos2d()
{
// init director
CCDirector *pDirector = CCDirector::getSharedDirector();
pDirector->setOpenGLView(m_pMainWnd);
// sets landscape mode
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// turn on display FPS
pDirector->setDisplayFPS(true);
2010-10-13 14:18:03 +08:00
// set the ResourceEntry and Images ResInfo (name and ResID)
2010-10-12 16:14:34 +08:00
UIImage::setResourceEntry(&Cocos2dSimpleGameResourceEntry);
UIImage::setImageResInfo(ResInfo, sizeof(ResInfo) / sizeof(T_ImageResInfo));
2010-10-13 14:18:03 +08:00
// set the ResourceEntry and sound ResInfo (filename and ResID)
SimpleAudioEngine::getSharedEngine()->setResourceEntry(&Cocos2dSimpleGameResourceEntry);
SimpleAudioEngine::getSharedEngine()->setSoundResInfo(SoundResInfo, sizeof(SoundResInfo) / sizeof(T_SoundResInfo));
2010-10-13 14:18:03 +08:00
// create a scene. it's an autorelease object
CCScene *pScene = HelloWorld::scene();
// run
CCDirector::getSharedDirector()->runWithScene(pScene);
return true;
}
AppDelegate::AppDelegate()
:m_rcWnd(0, 0, GetScreenWidth(), GetScreenHeight())
,m_pMainWnd(NULL)
{
}
AppDelegate::~AppDelegate()
{
}
Boolean AppDelegate::EventHandler(EventType* pEvent)
{
Boolean bHandled = FALSE;
switch(pEvent->eType)
{
case EVENT_AppLoad:
{
// it's important to use CCXEGLView, or you may inherit it to add your implement
if (! (m_pMainWnd = new CCXEGLView(this)) || ! m_pMainWnd->Create(&m_rcWnd))
{
// create window failed, quit application
SendStopEvent();
bHandled = TRUE;
break;
}
SetActiveWindow(m_pMainWnd);
// do not return bHandle equal TRUE, CCXApplication::EventHandler need do some thing.
break;
}
bHandled = TRUE;
break;
case EVENT_AppStopNotify:
{
}
bHandled = FALSE;
break;
}
return (bHandled) ? TRUE : CCXApplication::EventHandler(pEvent);
}