前端之家收集整理的这篇文章主要介绍了
cocos2dx Lua 笔记,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
好久没有写博客了 打算以后每天写一点 为爱好cocos2dx lua的爱好者贡献一点自己的绵薄之力
我使用的开发工具是vs2012 加lua插件这个网上很容易下载到 vs可以对lua进行调试并且有提示,
还有个小工具就是sublime 加上QuiteXdev 小插件开发起来不错
废话不扯了分享一下干货吧
我使用的版本是Quick-Cocos2dx-Community 3.6 Release
1,转世界坐标
node::convertToWorldSpace(node:getPostion())
2,加载精灵帧缓存
local spriteFrame = cc.SpriteFrameCache:getInstance()
spriteFrame:addSpriteFrames("particle.plist","particle.png")
ccs.GUIReader:getInstance():widgetFromJsonFile(jsonFile)
4,查找布局中的控件
ccui.Helper:seekWidgetByName(widget,name)
5,播放帧动画
local actionMgrEx = ccs.ActionManagerEx:getInstance()
actionMgrEx:playActionByName(MAIN_UI,"EnterAni")
6,播放骨骼动画 c++版
ArmatureDataManager::getInstance()->addArmatureFileInfo("NewAnimation/NewAnimation0.png" "NewAnimation/NewAnimation0.plist","NewAnimation/NewAnimation.ExportJson");
ArmatureDataManager::getInstance()->addArmatureFileInfo("NewAnimation/NewAnimation.ExportJson");
auto armature = Armature::create("NewAnimation");
armature->getAnimation()->play("Animation1");
7,声音播放
local fileUtils = cc.FileUtils:getInstance()
function MyApp:playMusic(musicfile,isLoop)
if fileUtils:isFileExist(fileUtils:fullPathForFilename(musicfile)) then
au
dio.playMusic(musicfile,isLoop)
if CONFIG_USER_DATA.MUSIC == 0 then
end
end
end
function MyApp:playSound(soundfile)
if fileUtils:isFileExist(fileUtils:fullPathForFilename(soundfile)) then
if CONFIG_USER_DATA.SOUND == 1 then
return au
dio.playSound(soundfile)
end
end
end
8,断点调试 vs 的配置demo
<?xml version="1.0"?>
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<propertyGroup>
<StartProgram>F:\cocos2d-x-work\player3\player3.exe</StartProgram>
<StartArguments>-workdir F:\cocos2d-x-work\cocoslua_project\shuihuzhuan\shuhui -file src\main.lua -portrait -size 640x960 -scale 0.75</StartArguments>
<StartWorkingDirectory>F:\cocos2d-x-work\player3</StartWorkingDirectory>
</propertyGroup>
</Project>
cocos2dx lua 爱好群489981799