因为VS2012创建默认文件是在proj.win32下,新建类不在VS的classes于是编译时找不到类。直接写个脚本帮助新建类(cpp和h文件),还能够在里面加上一些预先写好的代码。
批处理文件CreateClassInProject.bat,代码例如以下
@echo off echo CreateClassInProject: set /p projectName=Please Input Project Name: set /p className=Please Input Class Name: echo Creating... E:\cocos2d-x-3.0\CreateClassInProject.py -p %projectName% -n %className% CreateClassInProject.py -p HelloCocoStudio -n %className% echo Create successfully,Please add it in Classes. pause还有一个是python文件CreateClassInProject.py,我装的是python2.7.6,代码例如以下
import sys,os def createFileInClass(projectName,newClassName): print("001..."); projectDir = "projects\\"+projectName+"\\Classes"; #projectDir = "Classes"; os.chdir(projectDir); headName=newClassName+".h"; sourceName=newClassName+".cpp" headFile=open(headName,"a"); tempFileName = "_"+newClassName.upper()+"_H_"; headFile.write("#ifndef "+ tempFileName +"\n#define "+tempFileName+"\n\n") headFile.write("#include \"cocos2d.h\""+"\n\n"); headFile.write("using namespace cocos2d;\n\n"); headFile.write("class "+newClassName+"\n"+"{"+"\n"+"};"+"\n\n"+"#endif"); headFile.close(); sourceFile = open(sourceName,"a"); sourceFile.write("#include "+"\""+headName+"\""); sourceFile.close() from optparse import OptionParser print("002..."); parser = OptionParser() parser.add_option("-p", "--dir", dest="projectName",help="the project name",) parser.add_option("-n", "--new", dest="newClassName", help="new class") (options, args) = parser.parse_args() print("john..."); createFileInClass(options.projectName,options.newClassName)