Cocos2d-x by Example Beginner's Guide

司马德水
2023-12-01

01. Unleash(放出) your inner creativity an learn how to build great cross-plarform 2D games with the poplar Cocos2d-x framework.

书本中提到的reviewer的网站,有机会可以参考使用阅读。

有些应用实例很好,还是应该多向前辈学习。

http://www.michaelrjprice.com/

http://chatchaiwang.com/

02.书本中目录,还是要简单写写。

Chapter 1: Installing Cocos2d-x

Chapter 2: You Plus C++ Plus Cocos2d-x

Chapter 3: Your First Game - Air Hockey

Chapter 4: Fun with Sprites - Sky Defense

Chapter 5: On the Line - Rocket Through

Chapter 6: Quick and Easy Sprite - Victorian Rush Hour

Chapter 7: Adding the Looks - Victorian Rush Hour

Chapter 8: Getting Physical - Box2D

Chapter 9: On the Level - Eskimo

Chapter 10: Introducing Lua


Chapter 1: Installing Cocos2d-x

03. 可以这样编译android程序

cocos compile -p android

04. First you have the Classes folder; this will contain the classes for your application, and are written in C++. Below that is the Resources folder, where you find the images, fonts, and any kind of media used by the appliation.

05. In AppDelegate, you should set up the Director object (it is the Cocos2d-x all powerful singleton manager object), to run your application just the way you want. You can:

1. Get rid of the application status information.

2. Change the frame rate of your application

3. Tell Director where your high definition images are, and where your standard definition images are, as well as which to use.

4. You can change the overall scale of your application, so it will best fit different screens

5. The AppDelegate class is also the best placeto start any preloading process.

6. And most importantly, it is here tell the Director object what Scene to begin your application with.

05. 启动第一个scene

auto scene = HelloWorld::createScene();
director->runWithScene(scene);

06. A tool to help build sprite sheets: I'll use TexturePacker.

A tool to help build particle effects: I'll use Particle Designer.

A tool to help build bitmap fonts: I'll use Glyph Designer.

A tool to produce sound effects: No contest - sfxr for Windows or its Mac port cfxr.


Chapter 2: You Plus C++ Plus Cocos2d-x

07. The Containers are: Scene, Layer, and Sprite. They all inherit from a base container classes call node.

1. Scene: This will contain one or more Node, usually Layer types. It is common to break applications into multiple scenes; for instance, one for the main menu, one for setting, and one for the actual game. Technically, each scene will behave as a separate entity in your application, almost as subapplication themselves, and you can run a series of transition effects when changing between scenes.

2. Layer: This will most likely contain Sprite. There are a number of specialized Layer objects aimed at saving you, the developer, some time in creating things such as menu for instance (Menu), or a colored background (LayerColor). You can have more than one Layer per scene, but good planing makes this usually unnecessary.

3. Sprite: This will contain your images and be added as children to Layer derived containers. To my mind, this is the most important class in all of Cocos2d-x, so much so, that after your application initializes, when both a Scene and a Layer object are created, you could build your entire game only with sprites and never use another container class in Cocos2d-x.

4. Node: This super class to all containers blurs the line between itself and Layer, and even Sprite at times. It has its own set of specialized subclasses (besides the ones mentioned earlier), such as MotionStreak, ParallaxNode, and SpriteBatchNode, to name a few. It can, with a few adjustments, behave just as Layer. But most of the time you will use it to create your own specialized nodes or as a general reference in polymorphism.

08. After containers comes the all-knowing Director and all -encompassing cache objects.

The caches are collector objects. The most important ones are TextureCache, SpriteFrameCache, and AnimationCache.

Both Director and all cache objects are singletons. These are special sort of classes that are instantiated only once; and this one instance can be accessed y any other object.

08. Actions

Particles

Specialized nodes: For things such as menus, progress bars, special effects, parallax effect, tile maps, and much, much more.

The macro, structures, and helper methods: Hundreds of time-saving, magical bits of logic.

09. init comes from Layer and SimpleScene want to override it.


Chapter 5: On the Line - Rocket Through

这章的圆周运动的知识没有解决,导致这个游戏现在还无法正常运行。

第一版的源码有错误,所以修改之后仍然不能运行。

需要弄清楚游戏运动物理学的知识,必须深入理解相关的运动学知识,达到更真实的模拟效果。

有几本书下载:

Packt.Learning.Game.Physics.With.Bullet.Physics.And.OpenGL.Oct.2013.ISBN.1783281871

Introduction to game physic with Box2D

Game Physics 这是一本关于3D图形的书籍,后期掌握3D的时候在进行阅读。

前面三章主要结合

sprites, actions , particles在讲述,是cocos2d-x的基础知识。

仍然需要很努力才行,才能找到更好的出路。

有几个点需要掌握的是

1.怎么写触发时间,onTouchBegin的使用。

首先要写一个listener, 然后通过callback函数回调,具体的代码看下面。

2.继承layer类。

继承init()方法,写scene类。

3. update方法的利用。

update方法会根据游戏设置的帧,一秒钟调用多少次,默认是60次。

4. 绘画知识的学习。

这个是一个长期的过程,最近使用的软件是gimp,它里面有些例子,那就应该比较好上手。

80%的人只用到软件的20%的功能,所以绘画基础是关键。

5. 需要接触一个新的2d游戏物理引擎,box2d.


Chapter 6: Quick and Easy Sprite - Victorian Rush Hour

I'll show you a simple technique for rapid prototyping.

Rapid prototyping techniques allow you to test your game as early as possible in the development process as well as build up on the good ideas.

How to quickly create placeholder(占位符) sprites.

How to code collisions for a platform game.

How to create varied terrain(地形) for a side-scroller.

也算正式接触游戏有三个星期了,以我浅薄的知识来说还有很多需要学习。

虽然写得不完整,但是还是希望以我现在的认知来写。

2d游戏引擎cocos2d-x的学习,需要持续三个月。

基本掌握api的编写,以及游戏常见的使用。

另外cocos2d-x游戏源码的研究, 结合game engine architecture 这个书分析。

这个过程会碰到很多新的知识需要自己不断去巩固。

所以说这几个月的时间很重要,打好基础,基础基础。


关于美术也不能忘记,美术是一个长期的过程,有事没事可以琢磨琢磨怎么使用美术。

使用gimp作画,绘画板,这是个长期的过程。

15.

The controls are very simple: you tap the screen to make the cyclist jump and while he's in the air, if you tap the acreen again, the cyclist will open his trusty umbrella, either slowing his descent or adding a boost to his jump.

增加两点一个是github上下代码,不要下zip包了,直接下

git clone https://github.com/fmod/EarthWarrior3D

第二个是专业音频引擎 fmod的学习。

16. time for action

开始写Vir R游戏。





 类似资料: