axmol/HelloWorld.uphone/HelloWorld.cpp

100 lines
2.4 KiB
C++

// Application application cpp file.
// Original file name: HelloWorldApp.cpp
// Generated by TOPS Builder:Project wizard,Date:2010-8-3
#include "HelloWorld.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::sharedDirector()->end();
};
LAYER_NODE_FUNC(MyLayer);
};
// AppDelegate
HelloWorldAppDelegate::HelloWorldAppDelegate()
, m_pMainWnd(NULL)
{
}
bool HelloWorldAppDelegate::applicationDidFinishLaunching()
{
// init the window
if (!(m_pMainWnd = new CCXEGLView(this)) ||
! m_pMainWnd->Create(&TRectangle(0,0,GetScreenWidth(),GetScreenHeight())))
{
delete m_pMainWnd;
return false;
}
// init director
CCDirector::sharedDirector()->setOpenGLView(m_pMainWnd);
// set to landscape mode
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// load background image texture and get window size
CCTexture2D * pTexture = CCTextureCache::sharedTextureCache()->addImage(IMG_PATH);
CGSize size = CCDirector::sharedDirector()->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::sharedDirector()->runWithScene(pScene);
return true;
}
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void HelloWorldAppDelegate::applicationDidEnterBackground()
{
CCDirector::sharedDirector()->stopAnimation();
}
// this function will be called when the app is active again
void HelloWorldAppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->startAnimation();
}
// application main entry
Int32 TG3AppMain(const TUChar * pAppID, UInt32 nCmd, void * pCmdParam)
{
HelloWorldAppDelegate app;
return app.Run();
}