This commit is contained in:
walzer 2011-01-18 18:04:55 +08:00
commit 14a5470d72
11 changed files with 203 additions and 132 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

@ -9,10 +9,6 @@ using namespace CocosDenshion;
using namespace cocos2d;
[! if CCX_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
using namespace CocosDenshion;
[! endif]
AppDelegate::AppDelegate()
:m_pMainWnd(NULL)
{

View File

@ -18,3 +18,4 @@ protected:
};
#endif // __APP_DELEGATE_H__

View File

@ -4,14 +4,20 @@ using namespace cocos2d;
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene * scene = CCScene::node();
// 'layer' is an autorelease object
HelloWorld * layer = HelloWorld::node();
CCScene * scene = NULL;
do
{
// 'scene' is an autorelease object
scene = CCScene::node();
CCX_BREAK_IF(! scene);
// add layer as a child to scene
scene->addChild(layer);
// '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;
@ -20,49 +26,72 @@ 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 a menu item with "X" image, which is clicked to quit the program
// you may modify it.
CCX_BREAK_IF(! CCLayer::init());
// add a "close" icon to exit the progress. it's an autorelease object
CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback) );
pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
//////////////////////////////////////////////////////////////////////////
// add your codes below...
//////////////////////////////////////////////////////////////////////////
// create menu, it's an autorelease object
CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
pMenu->setPosition(CGPointZero);
this->addChild(pMenu);
// 1. Add a menu item with "X" image, which is clicked to quit the program.
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
CCLabelTTF* pLabel = CCLabelTTF::labelWithString("HelloWorld", "Thonburi", 64);
// 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);
// ask director the window size
CGSize size = CCDirector::sharedDirector()->getWinSize();
// Place the menu item bottom-right conner.
pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));
// position the label on the center of the screen
pLabel->setPosition(ccp(size.width / 2, size.height / 2));
// Create a menu with the "close" menu item, it's an auto release object.
CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
pMenu->setPosition(CGPointZero);
CCX_BREAK_IF(! pMenu);
// add the label as a child to this layer
this->addChild(pLabel);
return true;
// 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".
CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 64);
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));
// Add the label to HelloWorld layer as a child layer.
this->addChild(pLabel, 1);
// 3. Add add a splash screen, show the cocos2d splash image.
CCSprite* pSprite = CCSprite::spriteWithFile("HelloWorld.png");
CCX_BREAK_IF(! pSprite);
// 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

@ -1,5 +1,5 @@
#ifndef _HELLOWORLD_LAYER_H_
#define _HELLOWORLD_LAYER_H_
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
@ -29,4 +29,4 @@ public:
LAYER_NODE_FUNC(HelloWorld);
};
#endif // _HELLOWORLD_SCENE_H_
#endif // __HELLOWORLD_SCENE_H__

View File

@ -3,10 +3,10 @@ function OnFinish(selProj, selObj) {
var strProjectPath = wizard.FindSymbol('PROJECT_PATH');
var strProjectName = wizard.FindSymbol('PROJECT_NAME');
// var WizardVersion = wizard.FindSymbol('WIZARD_VERSION');
// if(WizardVersion >= 8.0)
// {
// }
// var WizardVersion = wizard.FindSymbol('WIZARD_VERSION');
// if(WizardVersion >= 8.0)
// {
// }
// Create symbols based on the project name
var strSafeProjectName = CreateSafeName(strProjectName);
@ -143,10 +143,10 @@ function AddConfigurations(proj, strProjectName) {
// General settings
var config = proj.Object.Configurations(astrConfigName[nCntr]);
// if(wizard.FindSymbol("CCX_USE_UNICODE"))
// if(wizard.FindSymbol("CCX_USE_UNICODE"))
config.CharacterSet = charSetUnicode;
// else
// config.CharacterSet = charSetMBCS;
// else
// config.CharacterSet = charSetMBCS;
config.OutputDirectory = '$(SolutionDir)$(ConfigurationName).win32'
config.IntermediateDirectory = '$(ConfigurationName).win32';
@ -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) {
@ -257,15 +257,15 @@ function AddConfigurations(proj, strProjectName) {
function AddPchSettings(proj) {
try {
// var files = proj.Object.Files;
// var fStdafx = files("StdAfx.cpp");
// var files = proj.Object.Files;
// var fStdafx = files("StdAfx.cpp");
//
// var nCntr;
// for(nCntr = 0; nCntr < nNumConfigs; nCntr++)
// {
// var config = fStdafx.FileConfigurations(astrConfigName[nCntr]);
// config.Tool.UsePrecompiledHeader = pchCreateUsingSpecific;
// }
// var nCntr;
// for(nCntr = 0; nCntr < nNumConfigs; nCntr++)
// {
// var config = fStdafx.FileConfigurations(astrConfigName[nCntr]);
// config.Tool.UsePrecompiledHeader = pchCreateUsingSpecific;
// }
}
catch (e) {
throw e;
@ -340,16 +340,16 @@ 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
if (strTarget == strProjectName + ".h" ||
strTarget == strProjectName + "ps.mk" ||
strTarget == strProjectName + "ps.def")
strTarget == strProjectName + "ps.mk" ||
strTarget == strProjectName + "ps.def")
continue;
proj.Object.AddFile(strFile);

View File

@ -1,5 +1,5 @@
#include "AppDelegate.h"
#include "cocos2d.h"
[! if CCX_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
#include "SimpleAudioEngine.h"
using namespace CocosDenshion;
@ -18,35 +18,37 @@ AppDelegate::AppDelegate()
AppDelegate::~AppDelegate()
{
[! if CCX_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
SimpleAudioEngine::release();
SimpleAudioEngine::end();
[! endif]
}
bool AppDelegate::applicationDidFinishLaunching()
{
// init the window
if (!(m_pMainWnd = new CCXEGLView()) ||
! m_pMainWnd->Create(L"cocos2d-win32", 320, 480) )
{
// init the window
if (!(m_pMainWnd = new CCXEGLView()) ||
! m_pMainWnd->Create(L"cocos2d-win32", 320, 480) )
{
CCX_SAFE_DELETE(m_pMainWnd);
return false;
}
return false;
}
// init director
CCDirector * pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(m_pMainWnd);
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// pDirector->setDeviceOrientation(kCCDeviceOrientationPortrait);
// pDirector->setDeviceOrientation(kCCDeviceOrientationPortrait);
pDirector->setDisplayFPS(true);
CCScene * pScene = HelloWorld::scene();
pDirector->runWithScene(pScene);
pDirector->runWithScene(pScene);
return true;
}
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
CCDirector::sharedDirector()->pause();
@ -56,6 +58,7 @@ void AppDelegate::applicationDidEnterBackground()
[! endif]
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->resume();

View File

@ -6,8 +6,8 @@
class AppDelegate : public cocos2d::CCXApplication
{
public:
AppDelegate();
~AppDelegate();
AppDelegate();
~AppDelegate();
virtual bool applicationDidFinishLaunching();
virtual void applicationDidEnterBackground();
@ -15,11 +15,6 @@ public:
protected:
cocos2d::CCXEGLView *m_pMainWnd;
// private:
// Int32 m_nTimer;
};
#endif // __APP_DELEGATE_H__
#endif // __APP_DELEGATE_H__

View File

@ -1,53 +1,97 @@
#include "HelloWorldScene.h"
using namespace cocos2d;
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::node();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::node();
CCScene * scene = NULL;
do
{
// 'scene' is an autorelease object
scene = CCScene::node();
CCX_BREAK_IF(! scene);
// add layer as a child to scene
scene->addChild(layer);
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::node();
CCX_BREAK_IF(! layer);
// return the scene
return scene;
// add layer as a child to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
bool bRet = false;
do
{
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
/////////////////////////////
// 2. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
CCLabel* pLabel = CCLabel::labelWithString("HelloWorld", "Thonburi", 64);
CCX_BREAK_IF(! CCLayer::init());
// ask director the window size
CGSize size = CCDirector::sharedDirector()->getWinSize();
//////////////////////////////////////////////////////////////////////////
// add your codes below...
//////////////////////////////////////////////////////////////////////////
// position the label on the center of the screen
pLabel->setPosition( ccp(size.width / 2, size.height / 2) );
// 1. Add a menu item with "X" image, which is clicked to quit the program.
// add the label as a child to this layer
this->addChild(pLabel);
return true;
// 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);
pMenu->setPosition(CGPointZero);
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".
CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 64);
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));
// Add the label to HelloWorld layer as a child layer.
this->addChild(pLabel, 1);
// 3. Add add a splash screen, show the cocos2d splash image.
CCSprite* pSprite = CCSprite::spriteWithFile("HelloWorld.png");
CCX_BREAK_IF(! pSprite);
// 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)
{
CCDirector::sharedDirector()->end();
// "close" menu item clicked
CCDirector::sharedDirector()->end();
}

View File

@ -1,6 +1,5 @@
#ifndef _HELLOWORLD_LAYER_H_
#define _HELLOWORLD_LAYER_H_
#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
@ -17,17 +16,17 @@
class HelloWorld : public cocos2d::CCLayer
{
public:
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// there's no 'id' in cpp, so we recommand to return the exactly class pointer
static cocos2d::CCScene* scene();
// a selector callback
virtual void menuCloseCallback(NSObject* pSender);
// there's no 'id' in cpp, so we recommand to return the exactly class pointer
static cocos2d::CCScene* scene();
// a selector callback
virtual void menuCloseCallback(NSObject* pSender);
// implement the "static node()" method manually
LAYER_NODE_FUNC(HelloWorld);
// implement the "static node()" method manually
LAYER_NODE_FUNC(HelloWorld);
};
#endif // _HELLOWORLD_SCENE_H_
#endif // __HELLOWORLD_SCENE_H__

View File

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