cocos2dx入门分析 hello world
打开新建的"findmistress"项目,可以看到项目文件是由多个代码文件及文件夹组成的,其中 Hello World 的代码文件直接存放于该项目文件夹中。下面我们来详细介绍一下项目的文件组成。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
//初始化游戏引擎控制器 Director,以便启动游戏引擎 // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { glview = GLView::create("My Game"); director->setOpenGLView(glview); }//启用 FPS 显示director->setDisplayStats(true); //设置绘制间隔 director->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object auto scene = HelloWorld::createScene(); // run director->runWithScene(scene); return true; |
|
1
2
3
4
5
6
7
8
|
// 'scene' is an autorelease objectauto scene = Scene::create();// 'layer' is an autorelease objectauto layer = HelloWorld::create();// add layer as a child to scenescene->addChild(layer); |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
//(1) 对父类进行初始化 if ( !Layer::init() ) { return false; }//(2) 创建菜单并添加到层 auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Point::ZERO); this->addChild(menu, 1);//(3) 创建"Hello World"标签并添加到层中 auto label = LabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen label->setPosition(Point(origin.x + visibleSize.width/2, origin.y + visibleSize.height - label->getContentSize().height)); // add the label as a child to this layer this->addChild(label, 1);//(4) 创建显示“HelloWorld.png”的精灵并添加到层中 // add "HelloWorld" splash screen" auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(sprite, 0); |
这段代码可以简单地划分为 4 个部分。
调用父类的 init 方法来进行最初的初始化。
创建关闭程序的菜单并添加到层中。
关于菜单以及下面提到的文本标签,我们也会在后面的章节中详细介绍。
创建一个文本标签并添加到层中,显示内容"Hello World"。
用"HelloWorld.png"创建一个精灵并添加到层中。最后程序返回 true,表示初始化成功。
在 C++中,一般习惯在构造函数中初始化类,然而由于 Cocos2d-x 的来源特殊,所以才没有采用 C++的编程风格。
cocos2dx入门分析 hello world的更多相关文章
- cocos2d-x入门学习笔记,主要介绍cocos2d-x的基本结构,并且介绍引擎自带的示例
cocos2d-x 3.0 制作横版格斗游戏 http://philon.cn/post/cocos2d-x-3.0-zhi-zuo-heng-ban-ge-dou-you-xi http://blo ...
- Cocos2d-x 源代码分析 : Scheduler(定时器) 源代码分析
源代码版本号 3.1r,转载请注明 我也最终不out了,開始看3.x的源代码了.此时此刻的心情仅仅能是wtf! !!!!!!! !.只是也最终告别CC时代了. cocos2d-x 源代码分析文件夹 h ...
- cocos2d-x 源代码分析 : EventDispatcher、EventListener、Event 源代码分析 (新触摸机制,新的NotificationCenter机制)
源代码版本号来自3.x,转载请注明 cocos2d-x 源代码分析总文件夹 http://blog.csdn.net/u011225840/article/details/31743129 1.继承结 ...
- cocos2d-x 源代码分析 : control 源代码分析 ( 控制类组件 controlButton)
源代码版本号来自3.1rc 转载请注明 cocos2d-x源代码分析总文件夹 http://blog.csdn.net/u011225840/article/details/31743129 1.继承 ...
- cocos2d-x入门学习笔记——Hello world分析
Hello world分析 1. “resource”文件夹 用于存放图片.音频和配置等资源文件.为了方便管理,可以创建在其中创建子文件夹.Cocos2d-x为我们屏蔽了不同平台对于文件路径的定义. ...
- cocos2d-x 发动机分析:程序如何开始和结束?
原创地址:http://game.dapps.net/gamedev/game-engine/9515.html 感谢原创分享! 怎么样使用 Cocos2d-x 高速开发游戏,方法非常easy,你能够 ...
- Cocos2d-x性能分析-Android版本之Gprof
在 iOS 平台下我们可以用 Xcode 自带的 Profile 工具来测试我们程序的性能,Android 平台使用的 gprof 这里整理了一下具体的cocos2dx 使用gprof进行性能分析的具 ...
- cocos2d-x 源代码分析 总文件夹
这篇博客用来整理与cocos2d-x相关的工作,仅仅要有新的分析.扩展或者改动,都会更改此文章. 祝大家愉快~ 1.源代码分析 1.CCScrollView源代码分析 http://blog.csdn ...
- cocos2d-x 源代码分析 : Ref (CCObject) 源代码分析 cocos2d-x内存管理策略
从源代码版本号3.x.转载请注明 cocos2d-x 总的文件夹的源代码分析: http://blog.csdn.net/u011225840/article/details/31743129 1.R ...
随机推荐
- Little Busters! — 并查集
题目链接:http://acm.buaa.edu.cn/problem/418/ 代码: #include<cstdio> #include<iostream> #includ ...
- First Adventures in Google Closure -摘自网络
Contents Introduction Background Hello Closure World Dependency Management Making an AJAX call with ...
- SSL 通信及 java keystore 工具介绍
http://www.javacodegeeks.com/2014/07/java-keystore-tutorial.html Table Of Contents 1. Introduction 2 ...
- 一个NB的安全认证机制
这是一个NB的安全认证机制. 1.这是一个安全认证机制 2.可以防止黑客截获到客户端发送的请求消息,避免了黑客冒充客户端向服务器发送操作的请求. 原理与步骤: 1.客户端与服务器端都会放着一份验证用的 ...
- Ubuntu 14.04 配置 Java SE
首先下载Java SE,下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html: 下载后把压缩包拷贝到自定义的目 ...
- SpringMVC 流程 配置 接口
SpringMVC简介 一 流程介绍 1.角色划分 前端控制器(DispatcherServlet).请求到处理器映射(HandlerMapping).处理器适配器(HandlerAdapter ...
- IIS- ASP站点布署时查看ASP错误信息
ASP使用的脚本是VBSCRIPT,布置的时候想显示他的错误信息,可以在INTERNET选项里把显示友好http错误信息的勾去掉 就能查看ASP布署时查看错误信息的勾去掉.
- javascript和php中的正则
正则: var subStr=str.replace(reg/str,''); 不改变原来的字符串返回替换后的字符窜; 如果不用正则,只能替换第一个匹配到的; var subStr=str.mat ...
- SampleManager(赛默飞)
- Ajax交互demo1
一.概念 Ajax异步请求刷新. 浏览器在用户不知道的情况下,偷偷地跟服务器交互,然后返回数据给浏览器显示. 异步过程:当HTTP请求发送后,通过Ajax技术使用的XMLHttpRequest对象来发 ...