如何在cocos2d-x 项目中增加全局变量
在项目中单独的文件保存这些东东,会很方便!
因而喜欢新建res类来存储,代码如下:
cocos2dx 定义全局变量
res.h里
#ifndef __RES_H__
#define __RES_H__
#include <iostream>
extern std::string strFile_Transfer;
extern bool IsSetFill;
#endif
/**********res.cpp定义全局变量************/
#pragma once
#include "res.h"
// 定义全局变量
std::string strFile_Transfer;
bool IsSetFill;
/**************************/
然后就可以头文件加res.h,直接用了 全局变量strFile_Transfer
我之前用char*类型的搞不定,好吧,还是string类型的简单,
要用char*可以通过string类型转换就行!嘻嘻~~
参考资料:http://blog.csdn.net/candyliuxj/article/details/7853938