"Mastering Cocos2d-x game development (basic volume)."

Chapter 1 Cocos2d-x sail

1.3 from 2.x to 3.x

  • The new C ++ 11 standard
  • Modified to render queue render tree
  • Name change style
  • Reconstruction of the message mechanism, adjust commissioned from mode to mode listener
  • Added 3D-related functions
  • Redo container, the waste container of a series of original custom STL directly Packaging containers
  • Simplify cross-platform project creation and packaging processes.
  • Node encapsulated in the physics engine, but the encapsulation is not appropriate.
  • ZOrder provides a global order, while related to rendering and click on touch.

1.4 Conventions

  • Abandoned Hungarian notation.

1.5 sail

1.5.1 Windows

Header file path, the library file path, and specify the link library files, these three questions and the corresponding number of errors will be accompanied by a beginner, here simply sort out:

  • C1083: Cannot open includefile: xxx.h No such file or directory。
  • LNK1104: unresolved external symbol.
  • LNK1104: Can not open file xxoo.lib.

1.5.4 Cocos engine

  • In the most familiar environment coded to improve development efficiency, understanding of each platform, to handle cross-platform compilation, packaging and development are of great help.

Chapter 2 Using Cocos2d-x

Before using a new technology, start with a simple understanding of the technology as a whole, and you will take some detours.

Lightweight game engine:

  • GDI
  • OpenGL
  • DirectX
  • HGE

2.1 Cocos2d-x world

  • The method of preparation of three kinds of commonly used logic.
    • Write logic node in an automatic callback method, init (), onEnter (), onExit ()
    • Use scheduler performs the timing logic, update ()
    • Callback after the specified event occurs
  • Get Input: Cocos2dx encapsulates at least two layers.
    • The first layer is the input interface platform dependent.
    • The second layer is the treated layer Cocos2dx message.

Chapter 3 stupid mistake Daquan

  • create和retain-release;
  • Inheritance create objects;
  • Performing a plurality of objects with the Action;
  • Forget virtual function is called the parent class;
  • Hidden code mysterious killer, node operation node;
  • Out of ordinary objects and new objects;
  • Do not forget to init;
  • addChild failure;
  • Call addChild parent in onEnter in;
  • Forget removed;
  • Overloaded draw precautions;
  • About references;
  • About namespace;
  • Class contains between about another;
  • About API platform-dependent;
  • About update the write logic;
  • About debugging;

Chapter 4 illustrates a pointer

4.1 Pointer and Memory

  • Classic question: const pointer and a pointer to a const object.
  • Identify techniques: *front number is a pointer type, *behind the number is modified to pointer.
  • Therefore const char* p1;the char const* p2same meaning pointer variable is immutable object.

4.2 Pointer operation

  • Pointer operation and basic operation of the pointer type hook operation:
  • Hook ->operation: . Member variables and member functions can manipulate objects.
  • Basic operation:
    • Dereference:* . The effect is equivalent to using the pointer into the object.
    • Arithmetic +operation: -, ++, --, . Offset 1 unit specifically how much? The pointer is set to the type of!
    • Allocation and newdeallocation: delete, new[], ,delete[]
    • Assignment operator:=
    • Analyzing ==operators: ,!=

4.3 pointers and arrays

  • Array (name) is itself a pointer.
  • Except that the sizeof(a)return is 4 * 4 size of the array, and sizeof(p)returns 4. The former to be tested .
  • Two-dimensional array of pointers and two relatively small.
  • Used int* pto specify two pointer b, p can be used to remove all of the elements in the two-dimensional array. For example, *ptake (0,0), *(p+4)take (1, 0).
  • To be tested , if possible, use two hands b itself can do the same thing?

4.4 function pointer

  • Ordinary function pointer can understand, member function pointers to the first contact, a little dizzy.
  • Defined functions and perform some functions are not the same.
  • Q: Why it is used as an ordinary function assigned when there is no ampersand, and member function pointers to add &.

4.5 wild pointer and memory leak

  • Null pointer: use will be reported null pointer exception. Solution: Before using judgment is not empty.
  • Wild pointers: pointing garbage memory (possibly random address), a non-null pointer field is determined not stay. The solution: do not point to NULL when the assignment statement, released after the memory is also pointing to NULL.
  • Memory leak: new heap memory out of memory has not been released, it is difficult to be found, the server program due to run for a long time will be a little serious. Solution: rely on programmers themselves. Detection methods: the constructor and destructor object to count, how many objects are created, how many objects are released after the end of the program is running to view the log.
// 定义静态变量
static int gGameObjectCount = 0;
// 构造函数打印统计
CGameObject::CGameObject(void)
{
	CCLog("CGameObject count %d", ++gGameObjectCount);
}
// 析构函数打印统计
CGameObject::~CGameObject(void)
{
	CCLog("~CGameObject count %d", --gGameObjectCount);
}

Chapter 5 C ++ 11 Introduction

  • Initialization list: simplify the code. std::initializer_list, Classes, functions, standard containers can be used.
  • Type inference: autoand decltype.
  • Range calculation: for(int &i : arr)simplified for loop code.
  • Smart pointers and null pointers: smart pointer is a class rather than general pointers. Null pointer nullptrtype nullptr_t, to solve the NULLambiguity problem. Implicit conversion is not an integer, and the integer can be compared.
void foo(char*);
void foo(int);
foo(NULL); // 执行的是foo(int)
foo(nullptr); // 执行的是foo(char*)
  • Lambda features:
  • Variable-length parameter template:
  • Rvalue references:
  • Explicit overloaded virtual function:



















Reference from "proficient Cocos2d-x game development (basic volume)."

Only learning exchanges, if infringement, please contact me delete.

Guess you like

Origin blog.csdn.net/fenglingfeixian/article/details/95956168