axmol/Helloworld-win32/Helloworld-win32.cpp

95 lines
2.3 KiB
C++
Raw Normal View History

2010-10-09 17:41:42 +08:00
// Helloworld-win32.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "Helloworld-win32.h"
using namespace cocos2d;
#define IMG_PATH "HelloWorld.png"
2010-10-11 17:26:01 +08:00
static HINSTANCE s_hInstance;
2010-10-09 17:41:42 +08:00
//////////////////////////////////////////////////////////////////////////
// implement MyLayer
//////////////////////////////////////////////////////////////////////////
class MyLayer : public CCLayer
{
public:
virtual void onEnter()
{
CCLayer::onEnter();
setIsTouchEnabled(true);
}
virtual bool ccTouchBegan(CCTouch *pTouch, UIEvent *pEvent)
{
CCDirector::sharedDirector()->end();
2010-10-09 17:41:42 +08:00
return true;
}
virtual void registerWithTouchDispatcher(void)
{
2010-11-16 16:15:21 +08:00
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,0,true);
2010-10-09 17:41:42 +08:00
}
};
//////////////////////////////////////////////////////////////////////////
// implement HelloWorldApplication
//////////////////////////////////////////////////////////////////////////
bool HelloWorldApplication::applicationDidFinishLaunching()
2010-10-09 17:41:42 +08:00
{
// init the window
if (!m_MainForm.Create(L"HelloWorld", 480, 320) )
{
return false;
}
2010-10-09 17:41:42 +08:00
// init director
CCDirector::sharedDirector()->setOpenGLView(&m_MainForm);
2010-10-09 17:41:42 +08:00
// load background image texture and get window size
CCTexture2D * pTexture = CCTextureCache::sharedTextureCache()->addImage(IMG_PATH);
CGSize size = CCDirector::sharedDirector()->getWinSize();
2010-10-09 17:41:42 +08:00
// create sprite instance
CCSprite * pSprite = new CCSprite();
pSprite->initWithTexture(pTexture);
pSprite->setPosition(CGPoint(size.width / 2, size.height / 2));
// create layer instance
2010-10-09 17:41:42 +08:00
CCLayer * pLayer = new MyLayer();
pLayer->addChild(pSprite);
// add layer to scene
CCScene * pScene = CCScene::node();
pScene->addChild(pLayer);
// add scene to director
CCDirector::sharedDirector()->runWithScene(pScene);
2010-10-09 17:41:42 +08:00
pSprite->release();
pLayer->release();
return true;
2010-10-09 17:41:42 +08:00
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
2010-10-11 17:26:01 +08:00
s_hInstance = hInstance;
2010-10-09 17:41:42 +08:00
2010-10-11 17:26:01 +08:00
int nRet = 0;
2010-10-09 17:41:42 +08:00
HelloWorldApplication app;
nRet = app.Run();
2010-10-11 17:26:01 +08:00
return nRet;
2010-10-09 17:41:42 +08:00
}