2010-10-09 17:41:42 +08:00
|
|
|
// Helloworld-win32.cpp : Defines the entry point for the application.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2010-11-17 11:13:37 +08:00
|
|
|
#include "Helloworld.win32.h"
|
2010-10-09 17:41:42 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2010-11-11 15:26:16 +08:00
|
|
|
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
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-11-12 16:25:14 +08:00
|
|
|
bool HelloWorldApplication::applicationDidFinishLaunching()
|
2010-10-09 17:41:42 +08:00
|
|
|
{
|
2010-11-12 16:25:14 +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
|
2010-11-11 15:26:16 +08:00
|
|
|
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);
|
2010-11-11 15:26:16 +08:00
|
|
|
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));
|
2010-10-10 21:03:11 +08:00
|
|
|
|
|
|
|
// 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
|
2010-11-11 15:26:16 +08:00
|
|
|
CCDirector::sharedDirector()->runWithScene(pScene);
|
2010-10-09 17:41:42 +08:00
|
|
|
|
|
|
|
pSprite->release();
|
|
|
|
pLayer->release();
|
|
|
|
|
2010-11-12 16:25:14 +08:00
|
|
|
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;
|
2010-11-12 16:25:14 +08:00
|
|
|
nRet = app.Run();
|
2010-10-11 17:26:01 +08:00
|
|
|
return nRet;
|
2010-10-09 17:41:42 +08:00
|
|
|
}
|