2010-07-26 17:12:06 +08:00
|
|
|
|
// Application application cpp file.
|
|
|
|
|
|
|
|
|
|
// Original file name: test_uphoneApp.cpp
|
|
|
|
|
// Generated by TOPS Builder:Project wizard,Date:2010-7-26
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "test_uphoneApp.h"
|
|
|
|
|
#include "test_uphoneMainForm.h"
|
2010-08-06 17:50:20 +08:00
|
|
|
|
#include "tests/controller.h"
|
2010-09-08 11:28:17 +08:00
|
|
|
|
|
|
|
|
|
// #include "CCDirector.h"
|
|
|
|
|
// #include "CCScene.h"
|
|
|
|
|
// #include "CCSprite.h"
|
|
|
|
|
// #include "tests/controller.h"
|
|
|
|
|
// #include "CCTextureCache.h"
|
2010-08-03 11:23:12 +08:00
|
|
|
|
|
2010-08-05 10:29:29 +08:00
|
|
|
|
using namespace cocos2d;
|
|
|
|
|
|
2010-08-17 15:01:09 +08:00
|
|
|
|
static void TimerCallback1(Int32 nTimerId, UInt32 uUserData);
|
|
|
|
|
|
2010-07-26 17:12:06 +08:00
|
|
|
|
Ttest_uphoneApp::Ttest_uphoneApp()
|
2010-08-03 11:23:12 +08:00
|
|
|
|
: m_pMainWnd(NULL)
|
2010-08-17 15:01:09 +08:00
|
|
|
|
, m_nTimer(0)
|
2010-07-26 17:12:06 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ttest_uphoneApp::~Ttest_uphoneApp()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-06 17:50:20 +08:00
|
|
|
|
bool Ttest_uphoneApp::initCocos2d()
|
2010-08-03 11:23:12 +08:00
|
|
|
|
{
|
2010-08-17 15:01:09 +08:00
|
|
|
|
// init director
|
2010-08-25 13:45:28 +08:00
|
|
|
|
CCDirector * pDirector = CCDirector::getSharedDirector();
|
|
|
|
|
pDirector->setOpenGLView(m_pMainWnd);
|
2010-09-09 16:15:21 +08:00
|
|
|
|
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
2010-09-18 15:21:13 +08:00
|
|
|
|
/*pDirector->setDeviceOrientation(kCCDeviceOrientationPortrait);*/
|
2010-08-25 13:45:28 +08:00
|
|
|
|
pDirector->setDisplayFPS(true);
|
2010-08-06 17:50:20 +08:00
|
|
|
|
|
2010-09-08 10:22:03 +08:00
|
|
|
|
// set the resource path
|
|
|
|
|
CCFileUtils::setResourcePath("/NEWPLUS/TDA_DATA/Data/cocos2d_tests/");
|
|
|
|
|
|
2010-08-17 15:01:09 +08:00
|
|
|
|
// load background image texture and get window size
|
2010-09-08 10:22:03 +08:00
|
|
|
|
CCTexture2D * pTexture = CCTextureCache::sharedTextureCache()->addImage("Images/HelloWorld.png");
|
2010-08-17 15:01:09 +08:00
|
|
|
|
CGSize size = CCDirector::getSharedDirector()->getWinSize();
|
|
|
|
|
|
|
|
|
|
// create sprite instance
|
2010-09-04 12:02:52 +08:00
|
|
|
|
CCSprite * pSprite = new CCSprite();
|
|
|
|
|
pSprite->initWithTexture(pTexture);
|
2010-08-17 15:01:09 +08:00
|
|
|
|
pSprite->setPosition(CGPoint(size.width / 2, size.height / 2));
|
2010-09-11 16:56:42 +08:00
|
|
|
|
pSprite->autorelease();
|
2010-08-17 15:01:09 +08:00
|
|
|
|
|
|
|
|
|
// create layer instance
|
|
|
|
|
CCLayer * pLayer = new CCLayer();
|
2010-09-11 16:56:42 +08:00
|
|
|
|
pLayer->addChild(pSprite);
|
|
|
|
|
pLayer->autorelease();
|
2010-08-06 17:50:20 +08:00
|
|
|
|
|
2010-08-17 15:01:09 +08:00
|
|
|
|
// add layer to scene
|
|
|
|
|
CCScene * pScene = CCScene::node();
|
2010-08-06 17:50:20 +08:00
|
|
|
|
pScene->addChild(pLayer);
|
2010-08-17 15:01:09 +08:00
|
|
|
|
|
|
|
|
|
// add scene to director
|
2010-08-06 17:50:20 +08:00
|
|
|
|
CCDirector::getSharedDirector()->runWithScene(pScene);
|
|
|
|
|
|
2010-08-17 15:01:09 +08:00
|
|
|
|
m_nTimer = TIMER_Create(3000, TIMER_MODE_NORMAL, TimerCallback1, 0, 0);
|
|
|
|
|
TIMER_Start(m_nTimer, 0);
|
|
|
|
|
|
2010-08-06 17:50:20 +08:00
|
|
|
|
return true;
|
2010-08-03 11:23:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-26 17:12:06 +08:00
|
|
|
|
Boolean Ttest_uphoneApp::EventHandler(EventType* pEvent)
|
|
|
|
|
{
|
|
|
|
|
Boolean bHandled = FALSE;
|
|
|
|
|
|
|
|
|
|
switch(pEvent->eType)
|
|
|
|
|
{
|
|
|
|
|
case EVENT_AppLoad:
|
|
|
|
|
{
|
2010-08-03 11:23:12 +08:00
|
|
|
|
m_pMainWnd = new TMainForm(this);
|
|
|
|
|
if (m_pMainWnd)
|
2010-07-26 17:12:06 +08:00
|
|
|
|
{
|
2010-08-03 11:23:12 +08:00
|
|
|
|
SetActiveWindow(m_pMainWnd);
|
2010-07-26 17:12:06 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ // <20><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3>˳<EFBFBD>Ӧ<EFBFBD>á<EFBFBD>
|
|
|
|
|
SendStopEvent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EVENT_AppStopNotify:
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
bHandled = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (FALSE == bHandled)
|
|
|
|
|
{
|
2010-08-03 11:23:12 +08:00
|
|
|
|
return CCXApplication::EventHandler(pEvent);
|
2010-07-26 17:12:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bHandled;
|
|
|
|
|
}
|
2010-08-17 15:01:09 +08:00
|
|
|
|
|
2010-09-25 11:54:33 +08:00
|
|
|
|
void Ttest_uphoneApp::applicationDidEnterBackground(TApplication* pApp)
|
|
|
|
|
{
|
|
|
|
|
CCDirector::getSharedDirector()->stopAnimation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Ttest_uphoneApp::applicationWillEnterForeground(TApplication* pApp)
|
|
|
|
|
{
|
|
|
|
|
CCDirector::getSharedDirector()->startAnimation();
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-17 15:01:09 +08:00
|
|
|
|
static void TimerCallback1(Int32 nTimerId, UInt32 uUserData)
|
|
|
|
|
{
|
2010-08-17 17:38:26 +08:00
|
|
|
|
CCScene * pScene = CCScene::node();
|
|
|
|
|
CCLayer * pLayer = new TestController();
|
|
|
|
|
pLayer->autorelease();
|
2010-08-17 15:01:09 +08:00
|
|
|
|
|
2010-08-17 17:38:26 +08:00
|
|
|
|
pScene->addChild(pLayer);
|
|
|
|
|
CCDirector::getSharedDirector()->replaceScene(pScene);
|
2010-08-17 15:01:09 +08:00
|
|
|
|
}
|