先说说接触编译游戏代码的感觉最深的几个地方,因为是第一次编译游戏的代码
最基本的创建一个项目
创建 hellogame项目
tools->cocos2d-console->bin->shift+右键->在此处打开命令窗口->路径pythoncocos.py newhellogame –p com.game.hellogame -lcpp -d game
1:在AppDelegate.cpp中有一串代码
if(!glview) {
//设置场景大小,保持和图片一致 ,Rect矩形,四个参数
//glview = GLViewImpl::create("My Game");
glview = GLViewImpl::createWithRect("plane", Rect(0, 0, 440, 664));
director->setOpenGLView(glview);
}
这个具体的参数,是根据你的场景大小决定的,也就是你的背景图片的大小
2:一些写类的共同点, 例如
在h文件中,开头都是这样编写,不同的类只需要改一下类名,
#include "cocos2d.h" 必须引用,有些函数或者API需要引用这个,
#ifndef _APP_DELEGATE_H_
#define _APP_DELEGATE_H_
#include "cocos2d.h"
在cpp文件中,开头是引用h的头文件
USING_NS_CC;必须引用, using namespace std;当使用字符串的时候也要引用
#include "AppDelegate.h"
#include "HelloWorldScene.h"
USING_NS_CC;
3:还有要注意的一点
#include "HelloWorldScene.h"
如果显示无法使用头文件,那就需要进行一个操作
Hellogame->属性-> C++ ->常规->添加包含目录->编辑->新行->debug.win32->确定
4:一般新建的 类里面就只有一个函数,
bool HelloWorld::init(){}
HelloWorld是类名,布尔型的init函数,里面可以编译你游戏想要实现的功能
使用这个函数的前提是在h 文件中申明这个函数
virtual bool init();