在win8+vs2012下配置cocos2d-x环境

来源:互联网 发布:对网络安全技术的认识 编辑:程序博客网 时间:2024/05/18 21:07

转自:http://www.cnblogs.com/zcmmwbd/archive/2012/08/30/2664156.html


在win8+vs2012下配置cocos2d-x环境

cocos2d-x是一个开源且跨平台的2D(游戏)引擎,运用甚广……

今天心血来潮打算学一下cocos2d-x,期间遇到了点小问题,于是乎把配置流程写出来让后来者可以有个参考。

 

这里假设你已安装WIN8和VS2012(非express版本)

 

1.下载cocos2d-1.0.1-x-0.12.0并解压(其他版本应该也差不多)

这就没啥好说的了,搜索引擎一搜一把。

解压到某个目录,这里用%COCOSROOT%来代替。

 

2.安装模板

安装前,需要先修改一下,使支持vs2012

你需要做的:

修改 %COCOSROOT%\install-templates-msvc.bat

复制代码
echo./*echo.* Install Cocos2d-win32 application wizard...echo.*/echo.set SCRIPT_LOG=InstallWizardLog.txtset SCRIPT_DIR=.\template\msvc\if exist %SCRIPT_LOG% del /Q %SCRIPT_LOG%cscript "%SCRIPT_DIR%InstallWizardForVC2008Express.js" /quietcscript "%SCRIPT_DIR%InstallWizardForVC2010Express.js" /quietcscript "%SCRIPT_DIR%InstallWizardForVS2008.js" /quietcscript "%SCRIPT_DIR%InstallWizardForVS2010.js" /quietcscript "%SCRIPT_DIR%InstallWizardForVS2012.js" /quietif exist %SCRIPT_LOG% more %SCRIPT_LOG%if exist %SCRIPT_LOG% del /Q %SCRIPT_LOG%
复制代码

 

创建 %COCOSROOT%\template\msvc\InstallWizardForVS2012.js  (这个文件是从VS2010的那个修改而来的)

复制代码
// Setup program for the Cocos2d-win32 App Wizard for VC++ 11.0 (VC2012)main();function EchoInfo(bQuiet, strMsg) {    if (! bQuiet) {        WScript.Echo(strMsg);    }    else {        var FileSys = new ActiveXObject("Scripting.FileSystemObject");        var strLogPath = "InstallWizardLog.txt"        var file = FileSys.OpenTextFile(strLogPath, 8, true);        file.WriteLine(strMsg);        file.Close();     }}function EchoError(bQuiet, strMsg) {    strMsg = "Error: " + strMsg;    if (! bQuiet) {        WScript.Echo(strMsg);    }    else {        var FileSys = new ActiveXObject("Scripting.FileSystemObject");        var strLogPath = "InstallWizardLog.txt"        var file = FileSys.OpenTextFile(strLogPath, 8, true);        file.WriteLine(strMsg);        file.Close();     }}function main() {    // Decode command line arguments    var bDebug = false;    var bQuiet = false;    var bElevated = false;    var Args = WScript.Arguments;    for (var i = 0; i < Args.length; i++) {        if (Args(i) == "/debug")            bDebug = true;        else if (Args(i) == "/elevated")            bElevated = true;        else if (Args(i) == "/quiet")            bQuiet = true;    }    // See if UAC is enabled    var Shell = WScript.CreateObject("Shell.Application");    if (!bElevated && Shell.IsRestricted("System", "EnableLUA")) {        // Check that the script is being run interactively.        if (!WScript.Interactive) {            EchoError(bQuiet, "(Windows LUA) Elevation required.");            return;        }        // Now relaunch the script, using the "RunAs" verb to elevate        var strParams = "\"" + WScript.ScriptFullName + "\"";        if (bDebug)            strParams += " /debug";        strParams += " /elevated";        Shell.ShellExecute(WScript.FullName, strParams, null, "RunAs");        return;    }    // Create shell object    var WSShell = WScript.CreateObject("WScript.Shell");    // Create file system object    var FileSys = WScript.CreateObject("Scripting.FileSystemObject");    // Get the folder containing the script file    var strScriptPath = FileSys.GetParentFolderName(WScript.ScriptFullName);    if (strScriptPath == null || strScriptPath == "")        strScriptPath = ".";    // Get the folder script files copy to    var strValue = "";    try {        var strVCKey = "HKLM\\Software\\Microsoft\\VisualStudio\\11.0\\Setup\\VC\\ProductDir";        strValue = WSShell.RegRead(strVCKey);    }    catch (e) {        try {            var strVCKey_x64 = "HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\11.0\\Setup\\VC\\ProductDir";            strValue = WSShell.RegRead(strVCKey_x64);        }        catch (e) {            EchoError(bQuiet, "Cannot find where Visual Studio 2012 is installed.");            return;        }    }    var strDestFolder = FileSys.BuildPath(strValue, "vcprojects");    if (bDebug)        WScript.Echo("Destination: " + strDestFolder);            if (!FileSys.FolderExists(strDestFolder)) {        EchoError(bQuiet, "Cannot find destination folder (should be: " + strDestFolder + ")");        return;    }    // Wizard Info    var nNumWizards = 2;    var astrWizardName = new Array();    astrWizardName[0] = "CCAppWiz.win32";    astrWizardName[1] = "CCAppWiz.wophone";    var nCntr;    for (nCntr = 0; nCntr < nNumWizards; nCntr++) {        var strSourceFolder = FileSys.BuildPath(strScriptPath, astrWizardName[nCntr]);        if (bDebug)            WScript.Echo("Source: " + strSourceFolder);        if (!FileSys.FolderExists(strSourceFolder)) {            EchoError(bQuiet, "Cannot find Wizard folder (should be: " + strSourceFolder + ")");            return;        }        // Copy files        try {            var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".ico");            var strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".ico");            FileSys.CopyFile(strSrc, strDest);            strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsdir");            strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".vsdir");            FileSys.CopyFile(strSrc, strDest);        }        catch (e) {            var strError = "no info";            if (e.description.length != 0)                strError = e.description;            EchoError(bQuiet, "Cannot copy file (" + strError + ")");            return;        }        // Read and write CCAppWiz.vsz, add engine version and replace path when found        try {            var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsz");            var strDest = FileSys.BuildPath(strDestFolder, astrWizardName[nCntr] + ".vsz");            var ForReading = 1;            var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);            if (fileSrc == null) {                EchoError(bQuiet, "Cannot open source file: " + strSrc);                return;            }            var ForWriting = 2;            var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);            if (fileDest == null) {                EchoError(bQuiet, " Cannot open destination file: " + strDest);                return;            }            while (!fileSrc.AtEndOfStream) {                var strLine = fileSrc.ReadLine();                if (strLine.indexOf("Wizard=VsWizard.VsWizardEngine") != -1)                    strLine += ".11.0";                else if (strLine.indexOf("WIZARD_VERSION") != -1)                    strLine = "Param=\"WIZARD_VERSION = 11.0\"";                else if (strLine.indexOf("ABSOLUTE_PATH") != -1)                    strLine = "Param=\"ABSOLUTE_PATH = " + strSourceFolder + "\"";                fileDest.WriteLine(strLine);            }            fileSrc.Close();            fileDest.Close();        }        catch (e) {            var strError = "no info";            if (e.description.length != 0)                strError = e.description;            EchoError(bQuiet, "Cannot read and write CCAppWiz.vsz (" + strError + ")");            return;        }    }    // Create Cocos2d-x folder    var strDestCCFolder = "";    try {        strDestCCFolder = FileSys.BuildPath(strDestFolder, "Cocos2d-x");        if (!FileSys.FolderExists(strDestCCFolder))            FileSys.CreateFolder(strDestCCFolder);        if (bDebug)            WScript.Echo("Cocos2d-x Folder: " + strDestCCFolder);    }    catch (e) {        var strError = "no info";        if (e.description.length != 0)            strError = e.description;        EchoError(bQuiet, "Cannot create Cocos2d-x folder (" + strError + ")");        return;    }    // Read and write additional CCAppWiz.vsdir and CCAppWiz.uphone.vsdir, add path to the wizard location    try {        var strDest = FileSys.BuildPath(strDestCCFolder, "Cocos2d-x.vsdir");        var ForWriting = 2;        var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);        if (fileDest == null) {            EchoError(bQuiet, "Cannot open destination file: " + strDest);            return;        }        var nCntr;        for (nCntr = 0; nCntr < nNumWizards; nCntr++) {            var strSourceFolder = FileSys.BuildPath(strScriptPath, astrWizardName[nCntr]);            var strSrc = FileSys.BuildPath(strSourceFolder, astrWizardName[nCntr] + ".vsdir");            var ForReading = 1;            var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);            if (fileSrc == null) {                EchoError(bQuiet, "Cannot open source file: " + strSrc);                return;            }            while (!fileSrc.AtEndOfStream) {                var strLine = fileSrc.ReadLine();                if (strLine.indexOf(astrWizardName[nCntr] + ".vsz|") != -1)                    strLine = "..\\" + strLine;                fileDest.WriteLine(strLine);            }            fileSrc.Close();        }        fileDest.Close();    }    catch (e) {        var strError = "no info";        if (e.description.length != 0)            strError = e.description;        EchoError(bQuiet, "Cannot read and write Cocos2d-x\\CCAppWiz.vsdir (" + strError + ")");        return;    }    EchoInfo(bQuiet, "App Wizard successfully installed for VS2012!");}
复制代码

 

修改完毕后,运行%COCOSROOT%\install-templates-msvc.bat即可

 

不出意外的话,你就可以在VS12的新建项目里头看到cocos2d-x的模板了

 

补充

1、在运行例子的时候,弹出这样的提示(因问题已解决,所有就没有截图)

PVR: VFrame attempted to use one of this functions
PVR: wglChoosePixelFormatARB
PVR: but they are not present on your machine

掏出win7下的显卡驱动(win8版本的驱动尚未发布,但vista、win7、win8的内核(驱动)程序在大部分情况下是可以兼容的),安装后即正常运行了。

 

2、用vs2012打开cocos2d-win32.vc2010.sln并升级至vs2012项目,可以正常编译所有工程。


0 0
原创粉丝点击