Cocos2d-x   发布时间:2022-05-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Cocos2dx -lua QuickXDev拓展大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

用cocos2d-x做开发的话,用的最多的开发语言就是c++/lua了,而现在公司很多都比较看重开发速度,较多的公司都选择了lua作为开发语言,同时lua的热更新也比c++的热更新更为便捷,更让更多的开发者都开始使用了lua进行开发。

作为手游开发者,自然不能落后^ ^。

开发工具的选择:sublime Text 。这里不选择coco官方的cocos code IDE 的理由是:api,各个方面插件功能支持不完善,基于eclpise的(之前在ADT遇到的种种问题,让我非常不爽,所以不喜欢!),内存占用问题(我电脑开着还想干其他事呢,怎么能卡呢? pass!),界面不简洁,不美观。然后么,基本上cocos code IDE 的不足之处都是sublime text的优势咯。

sublime 有功能众多的插件帮助开发者使用,界面精简,美观,占用内存小,开发速度快。而其中的QuickXDev插件,在基于quick的开发中,显得功能十分强大。

首先基本配置,选择QuickXDev 的setTing-user:(以下是我本地的配置)

{
    "quick_cocos2dx_root": "D:/cocos/quick-3.3","cocos2dx_root": "D:/cocos/quick-3.3","author": "cjsjy123","compile_scripts_key": "encrypt_key"
}
功能:

1.go to Definition,使其能够像IDE自由进行调整,查看这些api的具体实现和文档注释。

2.run with player ,快捷的启动player,查看运行效果。(这里可能会有问题,因为文档跳转用到了quick_cocos2dx_root 和cocos2dx_root的环境变量配置,如果在这里修改使之能运行player,则将无法正确跳转,所以在quickx.py(在sublime 打开brower packages ,找到QuickXDev的安装目录,找到它)中修改77行:

playerPath=quick_cocos2dx_root+"/quick/player/win32"+"/player3.exe"

就能正确的运行player了。

)

拓展:

实际上QuickXDev提供的api还是比较有限的,比如在quick中比较常用的display中的函数基本在api代码补全和提示中看不到,这点也是让我有点伤心啊,难道真的没办法了么?还是有的!

QuickXDev的api提示文件,我用python写了个,自动根据lua文件生成api提示的脚本,这个脚本的优势是能把当前文件夹下的所有.lua文件统一生成api提示,不仅仅是引擎的api,还有我们之前在程序中各个lua文件中的函数都能被智能识别,提示代码补全和提示功能,下面分享代码:

import os,sys,time
import Image
from kbtools import *

global mode
mode =[".lua",]

def Build_Snippet(fileName):
	if filename.endswith(mode[0]):
		m_filename=os.path.split(fileName)[-1]
		m_exportName =m_filename.split(".")[0]+"_export"
		if os.path.exists(os.path.abspath(m_exportName)) and os.path.isdir(os.path.abspath(m_exportName)):
			pass
		else:
			os.mkdir(os.path.abspath(m_exportName))
		print "export --- %s " %os.path.abspath(m_exportName)
		with open(filename,"rb") as f:
			for sub in f.readlines():
				passContent ="".join(sub.split())
				if passContent.startswith("function"):
					CreateSnip(passContent,filename,os.path.abspath(m_exportName))
			f.close()
		# with open(fileName)
	else:
		print "filename error"

def CreateSnip(String,fileVaule,dirName):
	param_list =[]
	left_index =String.find("(")
	right_index =String.find(")")
	index = String.find(".") 
	if  String.find(".")==-1  and String.find(":")==-1:
		return
	elif String.find(":") >left_index or index > left_index:
		return
	elif  String.find(".")!=-1  and String.find(":")!=-1:
		pass
	else:
		index =max(index,String.find(":"))
		
	Function_name = String[index+1:left_index]
	print "Function_name %s" %Function_name

	newstr = String[left_index+1:right_index]
	for substr in newstr.split(","):
		param_list.append(substr)
#start create
	file_content ="<snippet>\n"
	file_content += "\t<content><![CDATA["+Function_name+"("
	par_num = 0
	for each in param_list:
		if par_num ==len(param_list)-1:
			file_content +="${"+str(par_num)+":"+each+"})]]></content>\n"
		else:
			file_content +="${"+str(par_num)+":"+each+"},"
		par_num =par_num +1
	file_content +="\t<tabtrigger>"+String[index+1:len(String)]+"</tabtrigger>\n"
	file_content +="\t<scope>source.lua</scope>\n"
	file_content +="\t<description>"+fileVaule.split(".")[0].split("\\")[-1]+"</description>\n"
	file_content +="</snippet>"
	exportName =checkSNFile(os.path.split(fileVaulE)[-1]+"_"+Function_name)
	# print "  %s  fileVaule  %s" % (exportName,fileVaulE)
	with open(os.path.join(dirname,exportName),"w") as f:
		f.write(file_content)
		f.close()

def checkSNFile(fileName):
	newFile=filename
	if os.path.exists(fileName):
		mfile =filename.split(".")[0]
		newFile=mfile +"_extern"
		newFile =newFile.replace(".","_")
		newFile =newFile.replace(":","_")
		newFile += ".sublime-snippet"
		return checkSNFile(newFilE)
	else:
		if filename.endswith(".sublime-snippet") == True:
			newFile = filename.split(".")[0]
			newFile = newFile.replace(".","_")
			newFile = newFile.replace(":","_")
			newFile +=".sublime-snippet"
		else:
			newFile = filename.replace(".","_")
			newFile = filename.replace(":","_")
			newFile += ".sublime-snippet"
		return newFile

def setFlag(pmodE):
	global mode
	mode[0] =pmode

if __name__ =="__main__":
	if len(sys.argv) ==1:
		FileSearch(".",os.getcwd())
		for each in  get_allFile_list():
			Build_Snippet(each)
	input("finish__________")
	# Build_Snippet(os.path.join("a","display.lua"))
	pass

效果如下:


这样我们就能轻松愉快的进行lua编码,麻麻再也不怕我写错代码了!

脚本文件下载:点击打开链接

大佬总结

以上是大佬教程为你收集整理的Cocos2dx -lua QuickXDev拓展全部内容,希望文章能够帮你解决Cocos2dx -lua QuickXDev拓展所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。