2010-08-04 14:47:17 +08:00
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2010-08-04 14:47:17 +08:00
|
|
|
|
2010-08-06 10:15:54 +08:00
|
|
|
bool THelloWorldApp::initCocos2d()
|
2010-08-04 14:47:17 +08:00
|
|
|
{
|
2010-08-05 18:58:38 +08:00
|
|
|
// init director
|
2010-08-04 14:47:17 +08:00
|
|
|
CCDirector::getSharedDirector()->setOpenGLView(m_pMainWnd);
|
2010-08-05 11:02:30 +08:00
|
|
|
CCDirector::getSharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
2010-08-04 14:47:17 +08:00
|
|
|
|
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();
|
2010-08-04 14:47:17 +08:00
|
|
|
pScene->addChild(pLayer);
|
2010-08-05 18:58:38 +08:00
|
|
|
|
|
|
|
// add scene to director
|
2010-08-04 14:47:17 +08:00
|
|
|
CCDirector::getSharedDirector()->runWithScene(pScene);
|
2010-08-06 10:15:54 +08:00
|
|
|
return true;
|
2010-08-04 14:47:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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-05 17:20:24 +08:00
|
|
|
{
|
2010-08-06 09:55:37 +08:00
|
|
|
// create window failed, quit application
|
2010-08-05 17:20:24 +08:00
|
|
|
SendStopEvent();
|
2010-08-05 18:58:38 +08:00
|
|
|
bHandled = TRUE;
|
|
|
|
break;
|
2010-08-05 17:20:24 +08:00
|
|
|
}
|
2010-08-05 18:58:38 +08:00
|
|
|
SetActiveWindow(m_pMainWnd);
|
2010-08-05 17:20:24 +08:00
|
|
|
// do not return bHandle equal TRUE, CCXApplication::EventHandler need do some thing.
|
2010-08-04 14:47:17 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-08-05 18:58:38 +08:00
|
|
|
return (bHandled) ? TRUE : CCXApplication::EventHandler(pEvent);
|
|
|
|
}
|
2010-08-04 14:47:17 +08:00
|
|
|
|
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();
|
2010-08-04 14:47:17 +08:00
|
|
|
}
|