加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2dx Lua 笔记

发布时间:2020-12-14 17:19:18 所属栏目:百科 来源:网络整理
导读:好久没有写博客了 打算以后每天写一点 为爱好cocos2dx lua的爱好者贡献一点自己的绵薄之力 我使用的开发工具是vs2012 加lua插件这个网上很容易下载到 vs可以对lua进行调试并且有提示, 还有个小工具就是sublime 加上QuiteXdev 小插件开发起来不错 废话不扯了

好久没有写博客了 打算以后每天写一点 为爱好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")

3,加载布局文件
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
audio.playMusic(musicfile,isLoop)
if CONFIG_USER_DATA.MUSIC == 0 then
audio.pauseMusic()
end
end
end

function MyApp:playSound(soundfile)
if fileUtils:isFileExist(fileUtils:fullPathForFilename(soundfile)) then
if CONFIG_USER_DATA.SOUND == 1 then
return audio.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-workplayer3player3.exe</StartProgram>
<StartArguments>-workdir F:cocos2d-x-workcocoslua_projectshuihuzhuanshuhui -file srcmain.lua -portrait -size 640x960 -scale 0.75</StartArguments>
<StartWorkingDirectory>F:cocos2d-x-workplayer3</StartWorkingDirectory>
</propertyGroup>
</Project>




cocos2dx lua 爱好群489981799

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读