Cocos2d-x-Lua示例项目HelloLua(1)

建议先制定学习计划,根据学习计划把知识点关联起来,形成一个系统化的知识体系。同时我还搜集整理2020年字节跳动,以及腾讯,阿里,华为,小米等公司的面试题,把面试的要求和技术点梳理成一份大而全的“ Android架构师”面试 Xmind(实际上比预期多花了不少精力),包含。同时我还搜集整理2020年字节跳动,以及腾讯,阿里,华为,小米等公司的面试题,把面试的要求和技术点梳理成一份大而全的“ Android架构师”面试 Xmind(实际上比预期多花了不少精力),包含。但是如果你仅仅是看一遍,而不去学习和深究。
摘要由CSDN通过智能技术生成

if (engine->executeScriptFile(“src/main.lua”)) {

return false;

}

return true;

}

// This function will be called when the app is inactive. When comes a phone call,it’s be invoked too

// 当应用程序将要进入后台时,会调用这个方法

void AppDelegate::applicationDidEnterBackground()

{

Director::getInstance()->stopAnimation();

SimpleAudioEngine::getInstance()->pauseBackgroundMusic();

}

// this function will be called when the app is active again

// 该方法与applicationDidEnterBackground() 成对出现,在应用程序回到前台时被调用

void AppDelegate::applicationWillEnterForeground()

{

Director::getInstance()->startAnimation();

SimpleAudioEngine::getInstance()->resumeBackgroundMusic();

}

我们在AppDelegate类当中可以找到执行我们Lua脚本的方法,下面来看一下main.lua这个文件,我们屏幕显示的逻辑实现全部在这个文件中可以看到:

>>>main.lua

require “Cocos2d”

require “Cocos2dConstants”

– cclog

cclog = function(…)

print(string.format(…))

end

– for CCLuaEngine traceback 输出绑定执行函数发生错误的信息

function G__TRACKBACK(msg)

cclog(“----------------------------------------”)

cclog("LUA ERROR: " … tostring(msg) … “\n”)

cclog(debug.traceback())

cclog(“----------------------------------------”)

return msg

end

local function main()

collectgarbage(“collect”)

– avoid memory leak 这是脚本回收参数,避免内存泄漏

collectgarbage(“setpause”, 100)

collectgarbage(“setstepmul”, 5000)

– 追加资源的搜索顺序

cc.FileUtils:getInstance():addSearchResolutionsOrder(“src”);

cc.FileUtils:getInstance():addSearchResolutionsOrder(“res”);

local schedulerID = 0

–support debug 获取目标平台

local targetPlatform = cc.Application:getInstance():getTargetPlatform()

if (cc.PLATFORM_OS_IPHONE == targetPlatform) or (cc.PLATFORM_OS_IPAD == targetPlatform) or

(cc.PLATFORM_OS_ANDROID == targetPlatform) or (cc.PLATFORM_OS_WINDOWS == targetPlatform) or

(cc.PLATFORM_OS_MAC == targetPlatform) then

cclog("result is ")

–require(‘debugger’)()

end

– 类似c++的include,引入文件,会检查是否重复引入

require “hello2”

– 调用外部函数,在hello2.lua中

cclog("result is " … myadd(1, 1))


– 获取可视区域

local visibleSize = cc.Director:getInstance():getVisibleSize()

– 可视原点坐标 OpenGL坐标系,左下角为原点

local origin = cc.Director:getInstance():getVisibleOrigin()

– add the moving dog 添加移动的小松鼠

local function creatDog()

– 每一帧尺寸设置,local表示局部变量

local frameWidth = 105

local frameHeight = 95

– create dog animate 加载动画资源并创建精灵帧

– 加载精灵动画所在纹理

local textureDog = cc.Director:getInstance():getTextureCach

  • 20
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值