VS2010一鍵配置cocos2d x開發,帥呆了

2021-09-01 19:58:41 字數 4556 閱讀 6101

用vs2010開發cocos2d-x時,是不是很麻煩???在網上看了很多方法,沒乙個我喜歡的,都忒麻煩了,受不了, 自己寫了乙個指令碼,每次建立乙個新專案時,只要執行一下就行了。我們來看看**

# -*- coding: utf-8 -*-

import os

import shutil

''' 你需要自己把以下三個變數的值改為你自己實際的路徑,libdll根據自己需要新增 '''

cocos2dx = "d:\programtool\coco\cocos2d-2.1beta3-x-2.1.1"

cocoslibdll = "d:\programtool\coco\cocos2d-2.1beta3-x-2.1.1\debug.win32"

libdll = ["libcocos2d.lib", "libcocosdenshion.lib", "glew32.lib", "libbox2d.lib",

"libcocos2d.dll", "libcocosdenshion.dll", "glew32.dll", "libxml2.dll", "iconv.dll", "zlib1.dll", "libtiff.dll", "pthreadvce2.dll"]

def correctbase():

global cocos2dx

if os.path.isdir(cocos2dx) == false:

return false

if cocos2dx[len(cocos2dx)-2] != os.sep:

cocos2dx += os.sep

file = ["cocos2dx", "cocosdenshion", "external"]

for name in file:

if os.path.isdir(cocos2dx + name) == false:

return false

return cocos2dx

def change():

cocos2dx = correctbase()

if cocos2dx == false:

print("base dir \'cocos2dx\' is error ")

return

filelist = os.listdir(os.curdir)

for name in filelist:

if os.path.splitext(name)[1] != ".vcxproj":

continue

try:

file = open(os.curdir + os.sep +name, "r+", encoding = 'utf-8')

lines = file.readlines()

file.seek(0, os.seek_set)

file.truncate(0)

for oneline in lines:

if str.find(oneline, "") != -1:

line = oneline.replace("$(solutiondir)", cocos2dx)

file.write(line)

else:

file.write(oneline)

file.close()

except ioerror as e:

print(e)

def copylibdll():

global cocoslibdll

global libdll

if os.path.isdir(cocoslibdll) == false:

print("dir \'cocoslibdll\' is error ")

return

if cocoslibdll[len(cocoslibdll) - 2] != os.sep:

cocoslibdll += os.sep

if os.path.isdir("..\\..\\debug.win32") == false:

os.mkdir("..\\..\\debug.win32")

if os.path.isdir("..\\..\\release.win32") == false:

os.mkdir("..\\..\\release.win32")

for name in libdll:

filepath = cocoslibdll + name

if os.path.exists(filepath) == true:

if os.path.splitext(filepath)[1] == ".lib":

shutil.copy(filepath, os.getcwd())

else:

shutil.copy(filepath, "..\\..\\debug.win32")

shutil.copy(filepath, "..\\..\\release.win32")

def copypicture():

if os.path.isdir("..\\..\\debug.win32") == false:

os.mkdir("..\\..\\debug.win32")

if os.path.isdir("..\\..\\release.win32") == false:

os.mkdir("..\\..\\release.win32")

resourcedir = "..\\resources\\"

filename = ["closenormal.png", "closeselected.png", "helloworld.png"]

for name in filename:

filepath = resourcedir + name

if os.path.exists(filepath) == true:

shutil.copy(filepath, "..\\..\\debug.win32")

shutil.copy(filepath, "..\\..\\release.win32")

def changeusersetting():

filelist = os.listdir(os.curdir)

for name in filelist:

if os.path.splitext(name)[1] != ".user":

continue

try:

file = open(os.curdir + os.sep +name, "r+")

lines = file.readlines()

file.seek(0, os.seek_set)

file.truncate(0)

for oneline in lines:

if str.find(oneline, "$(projectdir)..\\resources") != -1 and str.find(oneline, "debug|win32") != -1:

line = oneline.replace("$(projectdir)..\\resources", "..\..\debug.win32")

file.write(line)

elif str.find(oneline, "$(projectdir)..\\resources") != -1 and str.find(oneline, "release|win32") != -1:

line = oneline.replace("$(projectdir)..\\resources", "..\..\release.win32")

file.write(line)

else:

file.write(oneline)

file.close()

except ioerror as e:

print(e)

if __name__ == "__main__":

change()

copylibdll()

copypicture()

changeusersetting()

現在,我們來看看這裡面都做了什麼事,首先,我會把工程的附加包含目錄中使用到的$(solutiondir)改為cocos2d-x所在的目錄,如下圖:

接著,我又把所有lib拷貝到當前資料夾,把所有dll拷貝到debug.win32和release.win32

然後呢,我又會把cocos2d-x自己生成的closenormal.png,closeselected.png,helloworld.png也拷貝到debug.win32和release.win32

最後,我把工作目錄也改到相應的debug.win32和release.win32,這樣就可以直接除錯了

就這麼簡單,乙個指令碼搞定,網上那些拷貝來拷貝去的做法忒麻煩了,有些博文甚至還說要拷貝到系統資料夾下。。。。

要把這個指令碼複製到專案工作目錄下哦,就是拷貝到***xx.win32.vcxproj檔案所在目錄,vs2012我沒安裝,沒測試過,用vs2012的朋友,自己測試一下哦

VS2010快捷鍵總結 一

1.f1 幫助 ctrl alt f1幫助目錄 ctrl f1 動態幫助 shift f1當前視窗幫助 f2 重新命名 f3 查詢下乙個 shift f3 查詢上乙個 ctrl alt f3幫助 搜尋 f4 顯示屬性視窗 shift f4顯示專案屬性視窗 ctrl f4關閉文件視窗 f5執行除錯 c...

VS2010 工程配置嚮導

1.新建工程 2.配置 general 通用 a.配置程式型別,exe or dll b.配置是否使用mfc庫 c.其他 3.c general 通用 a.配置要包含的標頭檔案路徑,通常是其他模組或者第三方庫標頭檔案所在路徑 4.c 生成 a.配置程式執行時庫型別,通常是mt multi threa...

VS2010版快捷鍵

vs2010版快捷鍵 ctrl e,d 格式化全部 ctrl e,f 格式化選中的 ctrl shift b生成解決方案 ctrl f7 生成編譯 ctrl o 開啟檔案 ctrl shift o開啟專案 ctrl shift c顯示類檢視視窗 f4 顯示屬性視窗 shift f4顯示專案屬性視窗 ...