– 显示到x=200,y=200的位置
child:setPosition( 200,200 )
ret:addChild(child, 1)
–Sum of all action’s duration is 1.5 second.
– 旋转一个节点,1.5秒,旋转90度
child:runAction(cc.RotateBy:create(1.5, 90))
– 执行动作序列,1.4秒延迟,淡出
child:runAction(cc.Sequence:create(cc.DelayTime:create(1.4),cc.FadeOut:create(1.1)))
local function removeThis()
– 溢出孩子
ret:getParent():removeChild(ret, true)
Helper.nextAction()
end
–After 1.5 second, self will be removed.
– 1.5秒之后,自身会被移除
ret:runAction( cc.Sequence:create(cc.DelayTime:create(1.4),cc.CallFunc:create(removeThis)))
return ret
end
–
– LogicTest
– 逻辑测试
local function LogicTest()
local ret = createTestLayer(“Logic test”)
– 精灵,s_pPathGrossini为图片路径
local grossini = cc.Sprite:create(s_pPathGrossini)
– 添加一个子节点到容器中,有Z轴顺序和一个标记。
ret:addChild(grossini, 0, 2)
grossini:setPosition(200,200)
local function bugMe(node)
– 停止所有动作
node:stopAllActions() --After this stop next action not working, if remove this stop everything is working
node:runAction(cc.ScaleTo:create(2, 2))
end
– 运行动作序列
grossini:runAction( cc.Sequence:create(cc.MoveBy:create(1, cc.p(150,0)) ,cc.CallFunc:create(bugMe)))
return ret
end
–
– PauseTest
– 暂停测试
local function PauseTest()
local ret = createTestLayer(“Pause Test”)
local schedulerEntry = nil
local function unpause(dt)
scheduler:unscheduleScriptEntry(schedulerEntry)
schedulerEntry = nil
local node = ret:getChildByTag( kTagGrossini )
local pDirector = cc.Director:getInstance()
pDirector:getActionManager():resumeTarget(node)
end
local function onNodeEvent(event)
– 进入时
if event == “enter” then
local s = cc.Director:getInstance():getWinSize()
local l = cc.Label:createWithTTF(“After 3 seconds grossini should move”, “fonts/Thonburi.ttf”, 16)
ret:addChild(l)
l:setAnchorPoint(cc.p(0.5, 0.5))
l:setPosition( cc.p(s.width / 2, 245) )
local grossini = cc.Sprite:create(s_pPathGrossini)
ret:addChild(grossini, 0, kTagGrossini)
grossini:setPosition(cc.p(200,200))
– 创建移动动作,持续时间1秒,移动到(150,0)的位置
local action = cc.MoveBy:create(1, cc.p(150,0))
local pDirector = cc.Director:getInstance()
– 通过获取director关联的ActionManager并为目标添加动作
– 为一个目标添加动作。 如果目标已经存在,动作将被加在已经存在的目标上。
– 如果目标不存在,将会创建这个目标的新对象,这个动作将被添加在这个新创建出来的对象上 当目标动作被暂停,动作队列的顺序也不会乱。
pDirector:getActionManager():addAction(action, grossini, true)
schedulerEntry = scheduler:scheduleScriptFunc(unpause, 3.0, false)
– 退出
elseif event == “exit” then
if schedulerEntry ~= nil then
scheduler:unscheduleScriptEntry(schedulerEntry)
end
end
end
– 注册响应事件
ret:registerScriptHandler(onNodeEvent)
return ret
end
–
– RemoveTest
–
local function RemoveTest()
local ret = createTestLayer(“Remove Test”)
local l = cc.Label:createWithTTF(“Should not crash”, “fonts/Thonburi.ttf”, 16)
– 获得屏幕大小
local s = cc.Director:getInstance():getWinSize()
ret:addChild(l)
l:setAnchorPoint(cc.p(0.5, 0.5))
l:setPosition( cc.p(s.width / 2, 245))
– 创建移动动作,持续2秒,到(200,0)的位置
local pMove = cc.MoveBy:create(2, cc.p(200, 0))
– 停止动作
local function stopAction()
– 根据Tag来获取子节点
local pSprite = ret:getChildByTag(kTagGrossini)
pSprite:stopActionByTag(kTagSequence)
end
– 创建一个回调函数
local callfunc = cc.CallFunc:create(stopAction)
local pSequence = cc.Sequence:create(pMove,callfunc)
pSequence:setTag(kTagSequence)
local pChild = cc.Sprite:create(s_pPathGrossini)
pChild:setPosition( 200, 200 )
ret:addChild(pChild, 1, kTagGrossini)
pChild:runAction(pSequence)
return ret
end
–
– ResumeTest
– 恢复测试
local function ResumeTest()
local ret = createTestLayer(“Resume Test”)
local schedulerEntry = nil
local function resumeGrossini(time)
scheduler:unscheduleScriptEntry(schedulerEntry)
schedulerEntry = nil
local pGrossini = ret:getChildByTag(kTagGrossini)
local pDirector = cc.Director:getInstance()
pDirector:getActionManager():resumeTarget(pGrossini)
end
local function onNodeEvent(event)
if event == “enter” then
local l = cc.Label:createWithTTF(“Grossini only rotate/scale in 3 seconds”, “fonts/Thonburi.ttf”, 16)
ret:addChild(l)
local s = cc.Director:getInstance():getWinSize()
l:setAnchorPoint(cc.p(0.5, 0.5))
l:setPosition( s.width / 2, 245)
local pGrossini = cc.Sprite:create(s_pPathGrossini)
ret:addChild(pGrossini, 0, kTagGrossini)
pGrossini:setPosition(200,200)
– 运行缩放的动作
pGrossini:runAction(cc.ScaleBy:create(2, 2))
local pDirector = cc.Director:getInstance()
– 暂停目标
pDirector:getActionManager():pauseTarget(pGrossini)
– 运行旋转动作,旋转360度,持续2秒
pGrossini:runAction(cc.RotateBy:create(2, 360))
schedulerEntry = scheduler:scheduleScriptFunc(resumeGrossini, 3.0, false)
elseif event == “exit” then
if schedulerEntry ~= nil then
scheduler:unscheduleScriptEntry(schedulerEntry)
end
end
end
ret:registerScriptHandler(onNodeEvent)
return ret
end
function ActionManagerTestMain()
cclog(“ActionManagerTestMain”)
Helper.index = 1 – 初始索引为1
– 设置深度测试
cc.Director:getInstance():setDepthTest(true)
– 创建场景
local scene = cc.Scene:create()
– 初始化方法表
Helper.createFunctionTable = {
CrashTest,
LogicTest,
PauseTest,
RemoveTest,
ResumeTest
}
– 添加层
scene:addChild(CrashTest())
scene:addChild(CreateBackMenuItem())
return scene
end
在例子中用到一些定义好的资源路径,还有相关帮助类,童鞋们可以到可以到相应目录下进行查找:
help.lua(帮助类,封装定义了相关方法,创建测试层、切换场景等)
require “Cocos2d”
CC_CONTENT_SCALE_FACTOR = function()
– 获取surface的大小,单位为像素
return cc.Director:getInstance():getContentScaleFactor()
end
–把以像素为单位的矩形转换为以点为单位的矩形
CC_POINT_PIXELS_TO_POINTS = function(pixels)
return cc.p(pixels.x/CC_CONTENT_SCALE_FACTOR(), pixels.y/CC_CONTENT_SCALE_FACTOR())
end
– 把以点为单位的矩形转换为以像素为单位的矩形
CC_POINT_POINTS_TO_PIXELS = function(points)
return cc.p(points.xCC_CONTENT_SCALE_FACTOR(), points.yCC_CONTENT_SCALE_FACTOR())
end
– cclog 打印日志
cclog = function(…)
print(string.format(…))
end
– change table to enum type 把表转换为枚举类型
function CreateEnumTable(tbl, index)
local enumTable = {}
local enumIndex = index or -1
for i, v in ipairs(tbl) do
enumTable[v] = enumIndex + i
end
return enumTable
end
– back menu callback 返回菜单回调
local function MainMenuCallback()
local scene = cc.Scene:create()
scene:addChild(CreateTestMenu())
– 切换场景
cc.Director:getInstance():replaceScene(scene)
end
– add the menu item for back to main menu
– 为返回主菜单添加菜单项
function CreateBackMenuItem()
– 创建一个标签
local label = cc.Label:createWithTTF(“MainMenu”, s_arialPath, 20)
– 设置器锚点
label:setAnchorPoint(cc.p(0.5, 0.5))
– 设置菜单项标签
local MenuItem = cc.MenuItemLabel:create(label)
MenuItem:registerScriptTapHandler(MainMenuCallback)
– 获得屏幕大小
local s = cc.Director:getInstance():getWinSize()
– 创建菜单
local Menu = cc.Menu:create()
– 添加菜单项
Menu:addChild(MenuItem)
– 设置菜单位置
Menu:setPosition(0, 0)
– 设置菜单项位置,大致在右下角的位置
MenuItem:setPosition(s.width - 50, 25)
return Menu
end
– 帮助类
Helper = {
index = 1, – 索引
createFunctioinTable = nil, – 存储方法的表
currentLayer = nil, – 当前层
titleLabel = nil, – 标题
subtitleLabel = nil – 子标题
}
– 下个动作
function Helper.nextAction()
Helper.index = Helper.index + 1 – 索引加1
if Helper.index > table.getn(Helper.createFunctionTable) then
Helper.index = 1
end
return Helper.newScene()
end
– 回退动作
function Helper.backAction()
Helper.index = Helper.index - 1
if Helper.index == 0 then
Helper.index = table.getn(Helper.createFunctionTable)
end
return Helper.newScene()
end
– 重新开始动作
function Helper.restartAction()
return Helper.newScene()
end
– 切换新的场景
function Helper.newScene()
local scene
– 如果使用物理效果
if Helper.usePhysics then
– 创建一个带物理效果的场景
scene = cc.Scene:createWithPhysics()
else
scene = cc.Scene:create()
end
Helper.currentLayer = Helper.createFunctionTableHelper.index
– 添加当前层
scene:addChild(Helper.currentLayer)
– 添加返回菜单
scene:addChild(CreateBackMenuItem())
– 切换场景
cc.Director:getInstance():replaceScene(scene)
end
– 初始化层
function Helper.initWithLayer(layer)
Helper.currentLayer = layer
– 获取屏幕大小
local size = cc.Director:getInstance():getWinSize()
Helper.titleLabel = cc.Label:createWithTTF(“”, s_arialPath, 28)
Helper.titleLabel:setAnchorPoint(cc.p(0.5, 0.5))
layer:addChild(Helper.titleLabel, 1)
Helper.titleLabel:setPosition(size.width / 2, size.height - 50)
Helper.subtitleLabel = cc.Label:createWithTTF(“”, s_thonburiPath, 16)
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
结语
网上高级工程师面试相关文章鱼龙混杂,要么一堆内容,要么内容质量太浅, 鉴于此我整理了上述安卓开发高级工程师面试题以及答案。希望帮助大家顺利进阶为高级工程师。
目前我就职于某大厂安卓高级工程师职位,在当下大环境下也想为安卓工程师出一份力,通过我的技术经验整理了面试经常问的题,答案部分是一篇文章或者几篇文章,都是我认真看过并且觉得不错才整理出来。
大家知道高级工程师不会像刚入门那样被问的问题一句话两句话就能表述清楚,所以我通过过滤好文章来帮助大家理解。
现在都说互联网寒冬,其实只要自身技术能力够强,咱们就不怕!我这边专门针对Android开发工程师整理了一套【Android进阶学习视频】、【全套Android面试秘籍】、【Android知识点PDF】。
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
,基本涵盖了95%以上Android开发知识点,真正体系化!**
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
结语
网上高级工程师面试相关文章鱼龙混杂,要么一堆内容,要么内容质量太浅, 鉴于此我整理了上述安卓开发高级工程师面试题以及答案。希望帮助大家顺利进阶为高级工程师。
目前我就职于某大厂安卓高级工程师职位,在当下大环境下也想为安卓工程师出一份力,通过我的技术经验整理了面试经常问的题,答案部分是一篇文章或者几篇文章,都是我认真看过并且觉得不错才整理出来。
大家知道高级工程师不会像刚入门那样被问的问题一句话两句话就能表述清楚,所以我通过过滤好文章来帮助大家理解。
[外链图片转存中…(img-aDJsrp8N-1713300647857)]
现在都说互联网寒冬,其实只要自身技术能力够强,咱们就不怕!我这边专门针对Android开发工程师整理了一套【Android进阶学习视频】、【全套Android面试秘籍】、【Android知识点PDF】。
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!