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"
|
|
|
|
|
2010-10-13 12:07:47 +08:00
|
|
|
// Layer
|
|
|
|
|
2010-09-11 12:02:43 +08:00
|
|
|
class MyLayer : public CCLayer
|
|
|
|
{
|
|
|
|
public:
|
2010-10-13 12:07:47 +08:00
|
|
|
bool init()
|
|
|
|
{
|
|
|
|
if( !CCLayer::init())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setIsTouchEnabled(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
2010-09-11 12:02:43 +08:00
|
|
|
|
2010-10-13 12:07:47 +08:00
|
|
|
void ccTouchesEnded(NSSet* pTouches, UIEvent* pEvent)
|
2010-09-11 12:02:43 +08:00
|
|
|
{
|
|
|
|
CCDirector::getSharedDirector()->end();
|
2010-10-13 12:07:47 +08:00
|
|
|
};
|
2010-09-11 12:02:43 +08:00
|
|
|
|
2010-10-13 12:07:47 +08:00
|
|
|
LAYER_NODE_FUNC(MyLayer);
|
2010-09-11 12:02:43 +08:00
|
|
|
};
|
|
|
|
|
2010-10-13 12:07:47 +08:00
|
|
|
// AppDelegate
|
|
|
|
|
2010-08-05 18:58:38 +08:00
|
|
|
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-10-13 12:07:47 +08:00
|
|
|
// set to landscape mode
|
2010-08-05 11:02:30 +08:00
|
|
|
CCDirector::getSharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
2010-10-13 12:07:47 +08:00
|
|
|
|
|
|
|
// load background image texture and get window size
|
|
|
|
CCTexture2D * pTexture = CCTextureCache::sharedTextureCache()->addImage(IMG_PATH);
|
|
|
|
CGSize size = CCDirector::getSharedDirector()->getWinSize();
|
2010-08-04 14:47:17 +08:00
|
|
|
|
2010-10-13 12:07:47 +08:00
|
|
|
// create sprite instance
|
|
|
|
CCSprite * pSprite = CCSprite::spriteWithTexture(pTexture);
|
|
|
|
pSprite->setPosition(CGPoint(size.width / 2, size.height / 2));
|
2010-08-05 18:58:38 +08:00
|
|
|
|
|
|
|
// create layer instance
|
2010-10-13 12:07:47 +08:00
|
|
|
CCLayer * pLayer = MyLayer::node();
|
|
|
|
pLayer->addChild(pSprite);
|
2010-08-05 18:58:38 +08:00
|
|
|
|
|
|
|
// 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-09-11 12:02:43 +08:00
|
|
|
|
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
|
|
|
}
|