axmol/test_uphone/test_uphoneApp.cpp

108 lines
2.4 KiB
C++
Raw Normal View History

// 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"
#include "CCDirector.h"
#include "CCScene.h"
#include "CCSprite.h"
#include "tests/controller.h"
#include "CCTextureCache.h"
using namespace cocos2d;
static void TimerCallback1(Int32 nTimerId, UInt32 uUserData);
Ttest_uphoneApp::Ttest_uphoneApp()
: m_pMainWnd(NULL)
, m_nTimer(0)
{
}
Ttest_uphoneApp::~Ttest_uphoneApp()
{
}
bool Ttest_uphoneApp::initCocos2d()
{
// init director
CCDirector::getSharedDirector()->setOpenGLView(m_pMainWnd);
CCDirector::getSharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// load background image texture and get window size
CCTexture2D * pTexture = CCTextureCache::sharedTextureCache()->addImage("/NEWPLUS/TDA_DATA/UserData/HelloWorld.png");
CGSize size = CCDirector::getSharedDirector()->getWinSize();
// create sprite instance
CCSprite * pSprite = (new CCSprite())->initWithTexture(pTexture);
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();
pScene->addChild(pLayer);
// add scene to director
CCDirector::getSharedDirector()->runWithScene(pScene);
m_nTimer = TIMER_Create(3000, TIMER_MODE_NORMAL, TimerCallback1, 0, 0);
TIMER_Start(m_nTimer, 0);
return true;
}
Boolean Ttest_uphoneApp::EventHandler(EventType* pEvent)
{
Boolean bHandled = FALSE;
switch(pEvent->eType)
{
case EVENT_AppLoad:
{
m_pMainWnd = new TMainForm(this);
if (m_pMainWnd)
{
SetActiveWindow(m_pMainWnd);
}
else
{ // <20><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3>˳<EFBFBD>Ӧ<EFBFBD>á<EFBFBD>
SendStopEvent();
}
}
break;
case EVENT_AppStopNotify:
{
}
bHandled = FALSE;
break;
}
if (FALSE == bHandled)
{
return CCXApplication::EventHandler(pEvent);
}
return bHandled;
}
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 17:38:26 +08:00
pScene->addChild(pLayer);
CCDirector::getSharedDirector()->replaceScene(pScene);
}