// Application application cpp file. // Original file name: HelloWorldApp.cpp // Generated by TOPS Builder:Project wizard,Date:2010-8-3 #include "HelloWorldApp.h" #include "cocos2d.h" using namespace cocos2d; #define IMG_PATH "/NEWPLUS/TDA_DATA/UserData/HelloWorld.png" // Layer class MyLayer : public CCLayer { public: bool init() { if( !CCLayer::init()) { return false; } this->setIsTouchEnabled(true); return true; }; void ccTouchesEnded(NSSet* pTouches, UIEvent* pEvent) { CCDirector::getSharedDirector()->end(); }; LAYER_NODE_FUNC(MyLayer); }; // AppDelegate THelloWorldApp::THelloWorldApp() : m_rcWnd(0, 0, GetScreenWidth(), GetScreenHeight()) , m_pMainWnd(NULL) { } bool THelloWorldApp::initCocos2d() { // init director CCDirector::getSharedDirector()->setOpenGLView(m_pMainWnd); // set to landscape mode CCDirector::getSharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); // load background image texture and get window size CCTexture2D * pTexture = CCTextureCache::sharedTextureCache()->addImage(IMG_PATH); CGSize size = CCDirector::getSharedDirector()->getWinSize(); // create sprite instance CCSprite * pSprite = CCSprite::spriteWithTexture(pTexture); pSprite->setPosition(CGPoint(size.width / 2, size.height / 2)); // create layer instance CCLayer * pLayer = MyLayer::node(); pLayer->addChild(pSprite); // add layer to scene CCScene * pScene = CCScene::node(); pScene->addChild(pLayer); // add scene to director CCDirector::getSharedDirector()->runWithScene(pScene); return true; } Boolean THelloWorldApp::EventHandler(EventType* pEvent) { Boolean bHandled = FALSE; switch(pEvent->eType) { case EVENT_AppLoad: 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; } return (bHandled) ? TRUE : CCXApplication::EventHandler(pEvent); } // application main entry Int32 TG3AppMain(const TUChar * pAppID, UInt32 nCmd, void * pCmdParam) { THelloWorldApp app; return app.Run(); }