Modify the template for win32.

Make it like the HelloWorld project.
This commit is contained in:
yangws 2011-01-18 11:45:22 +08:00
parent d2a116b001
commit a007aa5f84
5 changed files with 110 additions and 63 deletions

View File

@ -67,7 +67,7 @@ bool HelloWorld::init()
// position the sprite on the center of the screen
pSprite->setPosition( ccp(size.width/2, size.height/2) );
// ad the sprite as a child to this layer
// add the sprite as a child to this layer
this->addChild(pSprite, 0);
return true;

View File

@ -245,9 +245,9 @@ function AddConfigurations(proj, strProjectName) {
MidlTool.DLLDataFileName = "";
// Post-build settings
// var PostBuildTool = config.Tools("VCPostBuildEventTool");
// PostBuildTool.Description = "Performing registration...";
// PostBuildTool.CommandLine = "\"$(TargetPath)\" /RegServer";
var PostBuildTool = config.Tools("VCPostBuildEventTool");
PostBuildTool.Description = "Performing copy resource from Resource to OutDir...";
PostBuildTool.CommandLine = "copy /Y \"$(ProjectDir)Resource\\*.*\" \"$(OutDir)\"";
}
}
catch (e) {
@ -340,10 +340,10 @@ function AddFilesToCustomProj(proj, strProjectName, strProjectPath, InfFile) {
var strTemplate = strTemplatePath + '\\' + strTpl;
var strFile = strProjectPath + '\\' + strTarget;
var bCopyOnly = false; //"true" will only copy the file from strTemplate to strTarget without rendering/adding to the project
var bCopyOnly = true; //"true" will only copy the file from strTemplate to strTarget without rendering/adding to the project
var strExt = strName.substr(strName.lastIndexOf("."));
if (strExt == ".bmp" || strExt == ".ico" || strExt == ".gif" || strExt == ".rtf" || strExt == ".css")
bCopyOnly = true;
if (strExt == ".h" || strExt == ".cpp" || strExt == ".c" || strExt == ".rc")
bCopyOnly = false;
wizard.RenderTemplate(strTemplate, strFile, bCopyOnly);
// don't add these files to the project

View File

@ -5,14 +5,20 @@ using namespace cocos2d;
CCScene* HelloWorld::scene()
{
CCScene * scene = NULL;
do
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::node();
scene = CCScene::node();
CCX_BREAK_IF(! scene);
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::node();
CCX_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
@ -21,33 +27,70 @@ CCScene* HelloWorld::scene()
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
bool bRet = false;
do
{
return false;
}
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
/////////////////////////////
// 2. add your codes below...
CCX_BREAK_IF(! CCLayer::init());
// add a label shows "Hello World"
// create and initialize a label
CCLabel* pLabel = CCLabel::labelWithString("HelloWorld", "Thonburi", 64);
//////////////////////////////////////////////////////////////////////////
// add your codes below...
//////////////////////////////////////////////////////////////////////////
// ask director the window size
// 1. Add a menu item with "X" image, which is clicked to quit the program.
// Create a "close" menu item with close icon, it's an auto release object.
CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
CCX_BREAK_IF(! pCloseItem);
// Place the menu item bottom-right conner.
pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));
// Create a menu with the "close" menu item, it's an auto release object.
CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
CCX_BREAK_IF(! pMenu);
// Add the menu to HelloWorld layer as a child layer.
this->addChild(pMenu, 1);
// 2. Add a label shows "Hello World".
// Create a label and initialize with string "Hello World".
CCLabel* pLabel = CCLabel::labelWithString("Hello World", "Thonburi", 34);
CCX_BREAK_IF(! pLabel);
// Get window size and place the label upper.
CGSize size = CCDirector::sharedDirector()->getWinSize();
pLabel->setPosition(ccp(size.width / 2, size.height - 20));
// position the label on the center of the screen
pLabel->setPosition( ccp(size.width / 2, size.height / 2) );
// Add the label to HelloWorld layer as a child layer.
this->addChild(pLabel, 1);
// add the label as a child to this layer
this->addChild(pLabel);
// 3. Add add a splash screen, show the cocos2d splash image.
CCSprite* pSprite = CCSprite::spriteWithFile("HelloWorld.png");
CCX_BREAK_IF(! pSprite);
return true;
// Place the sprite on the center of the screen
pSprite->setPosition(ccp(size.width/2, size.height/2));
// Add the sprite to HelloWorld layer as a child layer.
this->addChild(pSprite, 0);
bRet = true;
} while (0);
return bRet;
}
void HelloWorld::menuCloseCallback(NSObject* pSender)
{
// "close" menu item clicked
CCDirector::sharedDirector()->end();
}

View File

@ -10,3 +10,7 @@ Classes/AppDelegate.cpp
Classes/HelloWorldScene.h
Classes/HelloWorldScene.cpp
Resource/CloseSelected.png
Resource/CloseNormal.png
Resource/HelloWorld.png