--动态数字
--@txt 文本节点
--@old 初始的数字
--@count 要增加的数字
--@callback 数字调完之后的回调函数
--@concat 单位
function UICommon.addNumEffect(txt,old,count,callback,concat)if count == 0 thentxt:setString(old..(type(concat) == "string" and concat or ""))returnendlocal time = 50local nowTime = 0local targetNum = old + countlocal perNum = nillocal mod = count % timelocal isSub = count < 0if isSub thencount = count + (time - (mod == 0 and time or mod))perNum = math.min(-1, math.floor(count / time))elsecount = count - modperNum = math.max(1, math.floor(count / time))endlocal function func()old = old + perNumtxt:setString(old..(type(concat) == "string" and concat or ""))if targetNum == old thentxt:unscheduleUpdate() if callback then callback() endreturnendnowTime = nowTime + 1if nowTime >= time then if isSub thenold = old - (time - (mod == 0 and time or mod))elseold = old + modendtxt:setString(old..(type(concat) == "string" and concat or ""))txt:unscheduleUpdate() if callback then callback() endendendtxt:scheduleUpdateWithPriorityLua(func, 0)
end--二级窗口弹出和关闭放大缩小的特效
function UICommon.openDialogAction(item,_scale,_dur)if item == nil then return endlocal scale =_scale or 0.9local dur =_dur or 0.2item:setScale(scale)local act1 = cc.EaseBackOut:create(cc.ScaleTo:create(dur, 1))item:runAction(act1)
end
function UICommon.closeDialogAction(item,callback)if item == nil then return endlocal act1 = cc.EaseBackIn:create(cc.ScaleTo:create(0.2, 0.9))local act2 = cc.CallFunc:create(callback)local seq = cc.Sequence:create(act1, act2)item:runAction(seq)
end-- 进度条动画
function UICommon.loadingTo(item,per,speedScale,reverse,callback)if item == nil then return endlocal perOld = item:getPercent()if reverse == nil then reverse = false endlocal flag = (reverse and perOld <= per) or (reverse == false and  perOld >= per)  -- 是否要再加载一遍local speed = (per==perOld and 100 or math.abs(per-perOld))/60 * (speedScale or 1)local function add()perOld = perOld + speedif flag thenif perOld >= 100 thenperOld = -speedflag = falseendelseif perOld >= per or perOld >= 100 thenitem:unscheduleUpdate()if callback then callback() endperOld = perendenditem:setPercent(perOld)endlocal function sub()perOld = perOld - speedif flag thenif perOld <= 0 thenperOld = 100 + speedflag = falseendelseif perOld <= per or perOld <= 0 thenitem:unscheduleUpdate()if callback then callback() endperOld = perendenditem:setPercent(perOld)endif reverse then     -- 反向item:scheduleUpdateWithPriorityLua(sub, 1)elseitem:scheduleUpdateWithPriorityLua(add, 1)end
end--输入框
--输入框统一通用
function UICommon.createEditBox(pnl,txt,color,holder,fontSize,maxNum,typeset,isSysFont,placeholderColor,offsetY)local inputSize = pnl:getContentSize()    local editMes = ccui.EditBox:create(inputSize,"assetsRes/res/beijing/beijing130.png")local function getTextNum()local strFmt = tools.filterSpecChars(editMes:getText())return strFmtendlocal function editBoxTextEventHandle(strEventName,pSender)if strEventName == "began" thenelseif strEventName == "ended" thenelseif strEventName == "return" theneditMes:setText(getTextNum())elseif strEventName == "changed" thengetTextNum()endendeditMes:setText(txt)editMes:registerScriptEditBoxHandler(editBoxTextEventHandle)    editMes:setPosition(cc.p(inputSize.width/2, inputSize.height/2 + (offsetY and offsetY or 0)))if not isSysFont theneditMes:setFontName(UICommon.getTTFName())endeditMes:setFontSize(fontSize)editMes:setFontColor(color)editMes:setName("editMes")if placeholderColor theneditMes:setPlaceholderFontColor(placeholderColor)endeditMes:setPlaceholderFontSize(fontSize)editMes:setPlaceHolder(holder)if maxNum theneditMes:setMaxLength(maxNum)endeditMes:setReturnType(cc.KEYBOARD_RETURNTYPE_DONE)pnl:addChild(editMes)
end-- 重复放大缩小
function UICommon.repeScale(item,args1,args2)args1 = UICommon.checkValid(args1)args2 = UICommon.checkValid(args2)local act1 = cc.ScaleTo:create(args1.time, args1.x,args1.y)local act2 = cc.ScaleTo:create(args2.time, args2.x,args2.y)local seq  = cc.Sequence:create(act1, act2)local action = cc.RepeatForever:create(seq)item:runAction(action)
end-- 重复渐隐和移动
function UICommon.repeatFadeAndMove(ltag, rtag)if not ltag or not rtag then return endlocal act1 = cc.MoveBy:create(1, {x=30})local act11 = act1:reverse()local act2 = cc.FadeOut:create(1)local act3 = cc.MoveBy:create(0, {x=-30})local act31 = act3:reverse()local act4 = cc.FadeIn:create(0.5)local seq1=cc.RepeatForever:create(cc.Sequence:create(cc.Spawn:create(act1,act2),act3,act4))local seq2=cc.RepeatForever:create(cc.Sequence:create(cc.Spawn:create(act11,act2),act31,act4))ltag:runAction(seq2:clone())rtag:runAction(seq1:clone())
end
-- 重复旋转
function UICommon.repeatRotateCircle(item)if item == nil then return endlocal repeatAction = cc.RepeatForever:create(cc.RotateBy:create(12, 360))item:runAction(repeatAction)
end
-- 重复变灰
function UICommon.repeatTintToGray(item)if item == nil then return endlocal action1 = cc.TintBy:create(0.5, -70, -70, -70)local action1Back = action1:reverse()local seq = cc.Sequence:create( action1, action1Back)local action = cc.RepeatForever:create(seq)item:runAction(action)
end
-- 停止变灰并恢复
function UICommon.stopTintAction(item)if item == nil then return endtransition.stopTarget(item)item:runAction(cc.TintTo:create(0, 255, 255, 255))
end
-- 向下移动并慢慢显示
function UICommon.moveDownAndFadeIn(item,delay)if item == nil then return enditem:setOpacity(0)item:moveBy({time = 0.6, y = -50})item:fadeIn({time = 0.6})
end
-- 重复来回透明度
function UICommon.repeatFade(item)if item == nil then return enditem:setOpacity(127)local action1 = cc.FadeTo:create(0.5,255)local action1Back = cc.FadeTo:create(0.5,127)local seq = cc.Sequence:create( action1, action1Back)local action = cc.RepeatForever:create(seq)item:runAction(action)
end
-- 停止来回透明度
function UICommon.stopRepeatFade(item)if item == nil then return endtransition.stopTarget(item)item:setOpacity(0)
end
-- 盖章效果
function UICommon.stampAction(item,cb,delayTime)if item == nil then return endlocal scaleNum = item:getScale()item:setScale(3 * scaleNum)item:setVisible(true)item:scaleTo({time = 0.2, scale = scaleNum, onComplete = function() delayCall(function() king:command("game.all.sealsomething") end, 50)  end})local delay = cc.DelayTime:create(math.max(delayTime or 0.25))local seal = cc.CallFunc:create(function()--音效if cb~=nil thencb();endend)local seq  = cc.Sequence:create(delay, seal)item:runAction(seq)
end
-- 向上移动并消失
function UICommon.moveUpAndFadeOut(item,delay)if item == nil then return endlocal act0 = cc.FadeIn:create(0)local act1 = cc.MoveBy:create(0.8, {y = 150})local act2 = cc.FadeOut:create(0.4)local act3 = cc.MoveBy:create(0, {y = -150})local seq  = cc.Sequence:create(act0, act1, act2, act3)local act  = transition.create(seq, {delay=delay or 0})item:runAction(act)
end
-- 渐隐消失
function UICommon.delayAndFadeOut(item,delay)if item == nil then return endlocal act0 = cc.FadeIn:create(0)local act1 = cc.DelayTime:create(delay)local act2 = cc.FadeOut:create(0.8)local act3 = cc.CallFunc:create(function()item:removeSelf()end)local seq  = cc.Sequence:create(act0, act1, act2, act3)item:runAction(seq)
end
-- 重复上下移动
function UICommon.repeatUpAndDown(item,spd,dis)if item == nil then return endlocal act1 = cc.MoveBy:create(spd or 1.2, {y = dis or 15})local seq  = cc.Sequence:create(act1, act1:reverse())local action = cc.RepeatForever:create(seq)item:runAction(action)
end

Lua游戏中常用到的一些动作相关推荐

  1. 游戏中常用的伪随机算法之PRD暴击算法

    游戏中常用的伪随机算法之PRD暴击算法 PRD伪随机算法常用于游戏中的暴击算法,因此本文的标题将其称为 PRD暴击算法. 诞生与应用 PRD算法诞生与<魔兽争霸3>,可以说其诞生就是为了解 ...

  2. 游戏中常用音乐风格分析

    不同的游戏有不同的玩法,每种不同的玩法都是不同的风格,每款游戏都配备了不同场景的音乐,根据音乐的场景不同,以及游戏风格的不同,游戏音乐风格也多种多样,今天我们来聊聊游戏音乐常用的风格有哪些? (一)按 ...

  3. 游戏中常用的寻路算法的分享(3):A*算法的实现

    概述 剥除代码,A* 算法非常简单.算法维护两个集合:OPEN 集和 CLOSED 集.OPEN 集包含待检测节点.初始状态,OPEN集仅包含一个元素:开始位置.CLOSED集包含已检测节点.初始状态 ...

  4. 游戏中常用的寻路算法(6):地图表示

    在本系列文档大部分内容中,我都假设A*用于某种网格上,其中的"节点"是一个个网格的位置,"边"是从某个网格位置出发的各个方向.然而,A*可用于任意图形,不仅仅是 ...

  5. 游戏中常用的设计模式

    内容会持续更新,有错误的地方欢迎指正,谢谢! 设计模式存在的意义:大多数是为了保证"低耦合高内聚" 1.单例模式 一个类只能有一个实例,单例非常重要经常用,比如游戏页面管理,现在我 ...

  6. 游戏中常用的寻路算法(5)预先计算好的路径的所用空间

    有时候,影响计算寻路路径的不是时间,而是计算路径所需的上百个单元格所占的空间.寻路是需要内存来运行寻路算法,还需要额外内存来存储寻到的路径.运行寻路算法(A*,开集或闭集)所需的临时空间经常会比存储这 ...

  7. 游戏中常用英文术语(动态更新)

    DPS:每秒伤害输出(DamagePerSecond):DOTA中后期型半后期型英雄(游戏前半期这种角色威力小,后期发挥重要作用,用于团队合作不错):魔兽世界中的伤害输出者(比如远程弓箭手,在多人合作 ...

  8. 游戏中常用的寻路算法的分享(2):Heuristics 函数

    转自:https://www.gameres.com/485150.html 启发式函数h(n)告诉A*从任何结点n到目标结点的最小代价评估值.因此选择一个好的启发式函数很重要. 启发式函数在A* 中 ...

  9. 游戏中常用的寻路算法的分享(4)处理移动中的障碍物

    一个寻路算法会计算出一条绕过静止障碍物的路径,但如果障碍物会移动呢?当一个单位移动到达某特定点时,原来的障碍物可能不在那点了,或者在那点上出现了新的障碍物.如果路线可以绕过典型的障碍物,那么只要使用单 ...

最新文章

  1. 【剑指offer】整数中1出现的次数,C++实现
  2. 消除8个关于AI在商业中应用的错误观念
  3. 盖茨:即使收购雅虎失败也要对决谷歌
  4. 【Qt】Qt中JSON简介
  5. 边缘计算和网络切片,为何成为5G的“技术网红”
  6. Ubuntu下用apache+perl搭建最简单的聊天室
  7. 【csust】最小素因子问题(树状数组)
  8. java基础知识汇总4
  9. 自定义view 写一个popup view
  10. linux 文件可执行_深入理解linux内核——可执行文件执行过程(2)
  11. 中国输卵管癌治疗行业市场供需与战略研究报告
  12. PyTorch基础(六)迁移学习
  13. bzoj 1656: [Usaco2006 Jan] The Grove 树木(BFS)
  14. 利用集成学习(Adaboost(DTs))对高光谱影像数据集(mat)分类
  15. mysql学习资料_PHP程序员2020学习方向:高并发、性能调优、分布式、微服务...
  16. H265 Vs VP9
  17. 【PyTorch深度学习项目实战100例】—— 基于CNN实现书法字体风格识别任务 | 第62例
  18. NewStarCTF2022-Week4-Web
  19. 使用Vue3学习Vue的基础知识
  20. 区块链支付和第三方支付区别

热门文章

  1. html占位符小于号,常用的一些占位符
  2. react-hooks+Ant Design Mobile中的自定义表单验证
  3. Velodyne CEO离职背后:风光不再,频频内斗,激光雷达巨头面临内忧外患
  4. STM32F0xx_PWR低功耗配置详细过程
  5. 英雄联盟怎么解除小窗口_英雄联盟手游亚索怎么操作-英雄联盟手游亚索操作攻略...
  6. python 效率 算法_python – 算法(prob solve)实现最快的运行时间
  7. 微软2012年4月最有价值专家(MVP)名单 51CTO十四位用户当选
  8. 看尚电视adb安装当贝桌面,并开机自启
  9. 亵渎小说介绍_亵渎行不通
  10. python能超越java吗_為什么Python能超越JAVA,有什么優勢?