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
|
|
|
|
|
2010-10-13 17:37:55 +08:00
|
|
|
#include "HelloWorld.h"
|
2010-08-04 14:47:17 +08:00
|
|
|
|
2010-08-05 18:58:38 +08:00
|
|
|
using namespace cocos2d;
|
|
|
|
|
2010-10-13 17:37:55 +08:00
|
|
|
#define IMG_PATH "/NEWPLUS/TDA_DATA/UserData/HelloWorld.png"
|
2010-08-05 18:58:38 +08:00
|
|
|
|
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
|
|
|
{
|
2010-11-11 11:18:58 +08:00
|
|
|
CCDirector::sharedDirector()->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-10-13 17:37:55 +08:00
|
|
|
HelloWorldAppDelegate::HelloWorldAppDelegate()
|
2010-11-18 23:55:00 +08:00
|
|
|
:m_pMainWnd(NULL)
|
2010-08-05 18:58:38 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2010-08-04 14:47:17 +08:00
|
|
|
|
2010-11-11 11:18:58 +08:00
|
|
|
bool HelloWorldAppDelegate::applicationDidFinishLaunching()
|
2010-08-04 14:47:17 +08:00
|
|
|
{
|
2010-11-11 11:18:58 +08:00
|
|
|
// init the window
|
2010-11-12 16:25:14 +08:00
|
|
|
if (!(m_pMainWnd = new CCXEGLView(this)) ||
|
|
|
|
! m_pMainWnd->Create(&TRectangle(0,0,GetScreenWidth(),GetScreenHeight())))
|
2010-11-11 11:18:58 +08:00
|
|
|
{
|
|
|
|
delete m_pMainWnd;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-05 18:58:38 +08:00
|
|
|
// init director
|
2010-11-11 11:18:58 +08:00
|
|
|
CCDirector::sharedDirector()->setOpenGLView(m_pMainWnd);
|
2010-10-13 12:07:47 +08:00
|
|
|
// set to landscape mode
|
2010-11-11 11:18:58 +08:00
|
|
|
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
2010-10-29 14:48:00 +08:00
|
|
|
|
2010-10-13 12:07:47 +08:00
|
|
|
// load background image texture and get window size
|
|
|
|
CCTexture2D * pTexture = CCTextureCache::sharedTextureCache()->addImage(IMG_PATH);
|
2010-11-11 11:18:58 +08:00
|
|
|
CGSize size = CCDirector::sharedDirector()->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-10-29 14:48:00 +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-11-11 11:18:58 +08:00
|
|
|
CCDirector::sharedDirector()->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
|
|
|
}
|
|
|
|
|
2010-10-29 14:48:00 +08:00
|
|
|
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
|
|
|
void HelloWorldAppDelegate::applicationDidEnterBackground()
|
|
|
|
{
|
2010-11-11 11:18:58 +08:00
|
|
|
CCDirector::sharedDirector()->stopAnimation();
|
2010-10-29 14:48:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// this function will be called when the app is active again
|
|
|
|
void HelloWorldAppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
2010-11-11 11:18:58 +08:00
|
|
|
CCDirector::sharedDirector()->startAnimation();
|
2010-10-29 14:48:00 +08:00
|
|
|
}
|
|
|
|
|
2010-08-05 18:58:38 +08:00
|
|
|
// application main entry
|
|
|
|
Int32 TG3AppMain(const TUChar * pAppID, UInt32 nCmd, void * pCmdParam)
|
|
|
|
{
|
2010-10-13 17:37:55 +08:00
|
|
|
HelloWorldAppDelegate app;
|
2010-08-06 09:48:18 +08:00
|
|
|
return app.Run();
|
2010-08-04 14:47:17 +08:00
|
|
|
}
|