C++语法app
一、在.H(头文件)文件里面进行声明,在CPP文件里面进行定义;spa
二、双冒号:: 是一个做用域操做符;作用域
//自动回收机制,当不用这个类的时候,自动回收it
CREATE_FUNC(HelloWorld);io
如何建立一个最简单的场景:class
新增一个类:object
而后在头文件处输入语法
#pragma once
#include "cocos2d.h"static
using namespace cocos2d;文件
class MyScene:public CCLayer
{
public:
MyScene();
~MyScene();
virtual bool init();
static CCScene* scene();
CREATE_FUNC(MyScene);
};
cpp文件中增长代码:
CCScene* MyScene::scene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
bool MyScene::init()
{
return true;
}
在AppDelegate.cpp文件下修改
bool AppDelegate::applicationDidFinishLaunching() 下的
auto scene = MyScene::scene();
Myscene为新建的类名