1 游戏逻辑架构,Cocos2d-x游戏项目创建,HelloWorld项目创建,HelloWorld程序分析,(CCApplicationProtocol,CCApplication,AppDeleg
1
游戏逻辑架构
具体介绍
A |
B sceneàaddChild(layer); layeràaddChild(sprite); |
2
项目创建命令:
A E:\Installed\cocos2d-x-2.2.3\tools\project-creator> |
B python create_project.py -project MyCocos2dx -package com.toto.mycocos01 -language cpp |
C -project MyCocos2dx工程名 -package com.toto.mycocos01 -language cpp |
D |
3
简单介绍
1 创建了一个cocos2dx项目之后,打开项目之后,会有例如以下项目结构 展开libcocos2d,找到cocos2d.cpp,双击打开此cpp文件,内容例如以下: #include NS_CC_BEGIN const { return } NS_CC_END 截图例如以下: 分析: A B |
2 |
程序入口是:main.cpp |
#include #include #include USING_NS_CC; int HINSTANCE LPTSTR int { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // create the application instance AppDelegate CCEGLView* eglView->setViewName("MyCocos2dx"); eglView->setFrameSize(480, return } |
进入run函数, |
int { PVRFrameEnableControlWindow(false); // Main message loop: MSG LARGE_INTEGER LARGE_INTEGER LARGE_INTEGER QueryPerformanceFrequency(&nFreq); QueryPerformanceCounter(&nLast); // Initialize instance and cocos2d. if (!applicationDidFinishLaunching()) { return 0; } CCEGLView* pMainWnd->centerWindow(); ShowWindow(pMainWnd->getHWnd(), while (1) { if (! { // Get current time tick. QueryPerformanceCounter(&nNow); // If it's the time to draw next frame, draw it, else sleep a while. if (nNow.QuadPart { nLast.QuadPart CCDirector::sharedDirector()->mainLoop(); } else { Sleep(0); } continue; } if (WM_QUIT { // Quit message loop. break; } // Deal with windows message. if (! { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int) } |
程序的入口:applicationDidFinishLaunching() |
AppDelegate.cpp bool // initialize director CCDirector* CCEGLView* pDirector->setOpenGLView(pEGLView); // turn on display FPS pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 // create a scene. it's an autorelease object CCScene *pScene // run pDirector->runWithScene(pScene); return } 截图: |
HelloWorldScene.h |
#ifndef #define #include class { public: // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone virtual // there's no 'id' in cpp, so we recommend returning the class instance pointer static // a selector callback void // implement the "static node()" method manually CREATE_FUNC(HelloWorld); }; #endif |
HelloWorldScene.cpp |
#include USING_NS_CC; CCScene* { // 'scene' is an autorelease object CCScene *scene // 'layer' is an autorelease object HelloWorld *layer // add layer as a child to scene scene->addChild(layer); //return the scene return } // on "init" you need to initialize your instance bool { ////////////////////////////// // 1. super init first if ( !CCLayer::init() { return } CCSize CCPoint ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x origin.y // create menu, it's an autorelease object CCMenu* pMenu->setPosition(CCPointZero); this->addChild(pMenu, ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label CCLabelTTF* // position the label on the center of the screen pLabel->setPosition(ccp(origin.x origin.y // add the label as a child to this layer this->addChild(pLabel, // add "HelloWorld" splash screen" CCSprite* // position the sprite on the center of the screen pSprite->setPosition(ccp(visibleSize.width/2 // add the sprite as a child to this layer this->addChild(pSprite, return } void { #if (CC_TARGET_PLATFORM CCMessageBox("You #else CCDirector::sharedDirector()->end(); #if (CC_TARGET_PLATFORM exit(0); #endif #endif } |
总结: 1、对于cocos真正的初始化是在init()方法中 2、CCScene中的 3、CCPointZero |
4
(CCApplicationProtocol,CCApplication,AppDelegate)三个类的类关系介绍:
抽出代码详细实现:
长处:屏蔽了平台的差异性,实现跨平台
1 #ifndef #define NS_CC_BEGIN enum { kTargetWindows, kTargetLinux, kTargetMacOS, kTargetAndroid, kTargetIphone, kTargetIpad, kTargetBlackBerry, kTargetNaCl, kTargetEmscripten, kTargetTizen, kTargetWinRT, kTargetWP8 }; /** * @addtogroup platform * @{ * @js NA * @lua NA */ class { public: virtual ~CCApplicationProtocol() /** @brief Implement CCDirector and CCScene init code here. @return true Initialize success, app continue. @return false Initialize failed, app terminate. */ virtual /** @brief The function be called when the application enter background @param the pointer of the application */ virtual /** @brief The function be called when the application enter foreground @param the pointer of the application */ virtual /** @brief Callback by CCDirector for limit FPS. @interval The time, expressed in seconds, between current frame and next. */ virtual /** @brief Get current language config @return Current language config */ virtual /** @brief Get target platform */ virtual }; // end of platform group /// @} NS_CC_END #endif |
2 |
3 |
1 游戏逻辑架构,Cocos2d-x游戏项目创建,HelloWorld项目创建,HelloWorld程序分析,(CCApplicationProtocol,CCApplication,AppDeleg的更多相关文章
- Django 创建web项目之HelloWorld
Django.Flask.Tornado并称为python WEB三大框架.Diango是一个开源的web应用框架,具有开发速度快的特点.同时因为过度封装,具有性能低的特点. 创建Django项目,启 ...
- 四、IntelliJ IDEA 之 HelloWorld 项目创建及相关配置文件介绍
咱们通过创建一个 Static Web 项目大致了解了 IntelliJ IDEA 的使用界面,接下来,趁着这个热乎劲,咱们来创建第一个 Java 项目“HelloWorld”,进入如下界面: 如上图 ...
- 关于eclipse创建Maven项目创建的问题
1.问题: 为什么Maven Update Project JDK变回1.5 解释:官方文档 The Compiler Plugin is used to compile the sources of ...
- tfs中如何创建团队项目及如何操作团队项目
创建团队项目集合 tfs server管理控制台\团队项目集合页面.选择'创建集合'链接,按向导即可创建项目集合. 创建团队项目 创建好团队项目集合后,就要开始创建团队项目了. 进入vs,连接上tfs ...
- 分模块创建maven项目(一)
maven是一个项目构建和管理的工具. 我们可以通过maven仓库可以实现管理构建(主要是JAR还包括:WAR,ZIP,POM等等). 我们可以通过maven插件可以实现编译源代.产生Javadoc文 ...
- IOS5基础教程之一-----如何创建XCode项目
一.IOS的基础知识 1.只有一个应用程序正在运行.在IOS上,每一段时间内只能激活一个应用程序并在屏幕上显示. 2.只有一个窗口.只允许应用程序操作的一个窗口. 3.访问受限.只能在IOS为应用程序 ...
- m2eclipse简单使用,创建Maven项目 ,运行mvn命令(转)
前面介绍了如何安装m2eclipse,现在,我们使用m2ecilpse导入Hello World项目. 选择菜单项File,然后选择Import,我们会看到一个Import对话框,在该对话框中选择Ge ...
- .Net Core .Net Core V1.0 创建MVC项目
.Net Core V1.0 创建MVC项目 创建MVC项目有两种方式: 一.创建Web项目:(有太多没用的东西要去删太麻烦) 2.项目目录结构: 此种方法要注意的是,会创建好多个json文件,下面就 ...
- Django 从0开始创建一个项目
title: Django 从0开始创建一个项目 tags: Django --- Django 从0开始创建一个项目 创建Django工程及配置 创建工程:django-admin starproj ...
随机推荐
- 对c#剪切板Clipboard占用的问题一点解决方法
以前在百度写的文档,转移到此处 前几天做一个程序,其中有一个剪切板的操作,具体代码: Clipboard.SetText(“ABC”); 来完成一个复制字符串的操作. 自己调试通过,完全正常,然后就交 ...
- 01串(dp)
01串 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 ACM的zyc在研究01串,他知道某一01串的长度,但他想知道不含有“11”子串的这种长度的01串共有多少个, ...
- 使用dojo的tree
dojo的Tree非常是灵活,可是官方站点上的样例却非常少,并且也比較分散,兴许将持续完好本样例. 总的来说,要使用tree,要接触到三个类:"dojo/store/JsonRest&quo ...
- jquery更新后怎样在一个站点中使用两个版本号的jQuery
公司眼下的项目中的右側导航菜单用到了bootstrap(v3.2.0)的affix.js(Affix插件)与scrospy.js(滚动监听)插件, 须要用到版本号>= 1.9.0的jquery, ...
- 前端编辑神器Brackets
介绍 Brackets 是Adobe发布的一款免费.开源且跨平台的 HTML/CSS/JavaScript 前端 WEB 集成开发环境.使用Node.js构建!官网:http://brackets.i ...
- Android 打造自己的个性化应用(二):应用程序内置资源实现换肤功能
通过应用程序内置资源实现换肤,典型的应用为QQ空间中换肤的实现. 应用场景为: 应用一般不大,且页面较少,风格相对简单,一般只用实现部分资源或者只用实现背景的更换. 此种换肤方式实现的思路: 1. 把 ...
- Microsoft Visual C++ 不支持long long
Microsoft Visual C++ 不支持long long 在C/C++中,64为整型一直是一种没有确定规范的数据类型.现今主流的编译器中,对64为整型的支持也是标准不一,形态各异.一般来说, ...
- MongoDB学习笔记04
创建索引使用ensureIndex方法,对于同一个集合,同样的索引只需要创建一次,反复创建是徒劳的. 对某个键的索引会加速对该键的查询,然而,对于其它查询可能没有帮助,即便是查询中包含了被索引的键.实 ...
- mysql中查看字符集的cmd指令
参看下面链接:http://blog.chinaunix.net/uid-20180960-id-1972668.html
- 【设计模式:单例模式】使用单例模式加载properties文件
先准备测试程序: package org.jediael.util; import static org.junit.Assert.*; import org.junit.Test; public c ...