axmol/HelloWorld/HelloWorldApp.cpp

74 lines
2.1 KiB
C++
Raw Normal View History

// Application application cpp file.
// Original file name: HelloWorldApp.cpp
// Generated by TOPS Builder:Project wizard,Date:2010-8-3
#include "HelloWorldApp.h"
2010-08-05 18:58:38 +08:00
#include "cocos2d.h"
using namespace cocos2d;
#define IMG_PATH "/NEWPLUS/TDA_DATA/UserData/HelloWorld.png"
THelloWorldApp::THelloWorldApp()
: m_rcWnd(0, 0, GetScreenWidth(), GetScreenHeight())
, m_pMainWnd(NULL)
{
}
bool THelloWorldApp::initCocos2d()
{
2010-08-05 18:58:38 +08:00
// init director
CCDirector::getSharedDirector()->setOpenGLView(m_pMainWnd);
CCDirector::getSharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
2010-08-05 18:58:38 +08:00
// load background image texture and get window size
2010-08-06 09:55:37 +08:00
CCTexture2D * pTexture = CCTextureCache::sharedTextureCache()->addImage(IMG_PATH);
2010-08-05 18:58:38 +08:00
CGSize size = CCDirector::getSharedDirector()->getWinSize();
// create sprite instance
2010-08-06 09:55:37 +08:00
CCSprite * pSprite = (new CCSprite())->initWithTexture(pTexture);
2010-08-05 18:58:38 +08:00
pSprite->setPosition(CGPoint(size.width / 2, size.height / 2));
pSprite->autorelease()->retain();
// create layer instance
CCLayer * pLayer = new CCLayer();
pLayer->addChild(pSprite)->autorelease();
// add layer to scene
CCScene * pScene = CCScene::node();
pScene->addChild(pLayer);
2010-08-05 18:58:38 +08:00
// add scene to director
CCDirector::getSharedDirector()->runWithScene(pScene);
return true;
}
Boolean THelloWorldApp::EventHandler(EventType* pEvent)
{
Boolean bHandled = FALSE;
switch(pEvent->eType)
{
case EVENT_AppLoad:
2010-08-05 18:58:38 +08:00
if (! (m_pMainWnd = new CCXEGLView(this)) || ! m_pMainWnd->Create(&m_rcWnd))
{
2010-08-06 09:55:37 +08:00
// create window failed, quit application
SendStopEvent();
2010-08-05 18:58:38 +08:00
bHandled = TRUE;
break;
}
2010-08-05 18:58:38 +08:00
SetActiveWindow(m_pMainWnd);
// do not return bHandle equal TRUE, CCXApplication::EventHandler need do some thing.
break;
}
2010-08-05 18:58:38 +08:00
return (bHandled) ? TRUE : CCXApplication::EventHandler(pEvent);
}
2010-08-05 18:58:38 +08:00
// application main entry
Int32 TG3AppMain(const TUChar * pAppID, UInt32 nCmd, void * pCmdParam)
{
2010-08-06 09:48:18 +08:00
THelloWorldApp app;
return app.Run();
}