--非cocos自带的扩展action统一放这里
|
|
cc = cc or {}
|
|
|
|
cc.NumberBy = cc.NumberBy or BaseClass(cc.ActionInterval)
|
|
|
|
--isInteger表示数字是否以整数改变
|
|
function cc.NumberBy:__init(duration, deltaNum, isInteger,fmt)
|
|
self:initWithDuration(duration, deltaNum, isInteger,fmt)
|
|
end
|
|
|
|
function cc.NumberBy:initWithDuration(duration, deltaNum, isInteger,fmt)
|
|
cc.ActionInterval.initWithDuration(self, duration)
|
|
if isInteger == nil then
|
|
isInteger = true
|
|
end
|
|
self.isInteger = isInteger
|
|
self.deltaNum = deltaNum
|
|
self.fmt = fmt
|
|
end
|
|
|
|
function cc.NumberBy:clone()
|
|
return cc.NumberBy.New(self._duration, self.deltaNum, self.isInteger)
|
|
end
|
|
|
|
function cc.NumberBy:startWithTarget(target)
|
|
cc.ActionInterval.startWithTarget(self, target)
|
|
self.previousNum = target:GetComponent("Text").text
|
|
end
|
|
|
|
function cc.NumberBy:reverse()
|
|
return cc.NumberBy.New(self._duration, -self.deltaNum, self.isInteger)
|
|
end
|
|
|
|
function cc.NumberBy:update(t)
|
|
if (self._target) then
|
|
local newNum = tonumber(self.previousNum) + self.deltaNum * t
|
|
if self.isInteger then
|
|
newNum = math.floor(newNum)
|
|
end
|
|
if self.fmt then
|
|
newNum = string.format(self.fmt,newNum)
|
|
end
|
|
-- print("Cat:CCActionExtend.lua [36] newNum,self.isInteger,self.previousNum,self.deltaNum: ",newNum,self.isInteger,self.previousNum,self.deltaNum)
|
|
if self._target:GetComponent("Text") then
|
|
self._target:GetComponent("Text").text = newNum
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
cc.NumberTo = cc.NumberTo or BaseClass(cc.NumberBy)
|
|
|
|
--isInteger表示数字是否以整数改变
|
|
function cc.NumberTo:__init(duration, targetNum, isInteger,fmt)
|
|
self:initWithDuration(duration, targetNum, isInteger,fmt)
|
|
end
|
|
|
|
function cc.NumberTo:initWithDuration(duration, targetNum, isInteger,fmt)
|
|
cc.ActionInterval.initWithDuration(self, duration)
|
|
if isInteger == nil then
|
|
isInteger = true
|
|
end
|
|
self.isInteger = isInteger
|
|
self.targetNum = targetNum
|
|
self.fmt = fmt
|
|
end
|
|
|
|
function cc.NumberTo:clone()
|
|
return cc.NumberTo.New(self._duration, self.targetNum, self.isInteger)
|
|
end
|
|
|
|
function cc.NumberTo:startWithTarget(target)
|
|
cc.ActionInterval.startWithTarget(self, target)
|
|
self.previousNum = 0
|
|
if target:GetComponent("Text") then
|
|
self.previousNum = target:GetComponent("Text").text
|
|
end
|
|
self.deltaNum = tonumber(self.targetNum or 0)-tonumber(self.previousNum or 0)
|
|
end
|
|
|
|
function cc.NumberTo:reverse()
|
|
return nil
|
|
end
|
|
-- function cc.NumberTo:update(t)
|
|
-- if (self._target) then
|
|
-- local newNum = self.previousNum + self.deltaNum * t
|
|
-- if self.isInteger then
|
|
-- newNum = math.floor(newNum)
|
|
-- end
|
|
-- -- print("Cat:CCActionExtend.lua [36] newNum,self.isInteger,self.previousNum,self.targetNum: ",newNum,self.isInteger,self.previousNum,self.targetNum)
|
|
-- self._target:setNumber(newNum)
|
|
-- end
|
|
-- end
|
|
|
|
--不断地移动并渐现的动作
|
|
cc.FloatFadeIn = cc.FloatFadeIn or {}
|
|
function cc.FloatFadeIn.New(start_x, start_y, offset_x, offset_y, float_duration, stay_duration)
|
|
float_duration = float_duration or 1.0
|
|
stay_duration = stay_duration or 1.0
|
|
start_x = start_x or 0
|
|
start_y = start_y or 0
|
|
offset_x = offset_x or 0
|
|
offset_y = offset_y or -50
|
|
|
|
local move_up = cc.MoveBy.New(float_duration, offset_x, offset_y)
|
|
action = cc.Sequence.New(move_up, cc.DelayTime.New(stay_duration), cc.Place.New(start_x, start_y))
|
|
action = cc.RepeatForever.New(action)
|
|
return action
|
|
end
|
|
|
|
--[[
|
|
<*
|
|
@Author: ZensYue
|
|
@Description: 获取通用scale运动 支持普通widget
|
|
@param: pos 初始坐标 格式[x,y]
|
|
@param: size 初始大小 格式[x,y]
|
|
@param: scale 缩放值
|
|
@param: time 运动时间
|
|
@return: action
|
|
*>
|
|
]]
|
|
-- cc.Scale = cc.Scale or {}--废弃
|
|
-- function cc.Scale.New(pos,size,scale,time)
|
|
-- local x,y = pos.x,pos.y
|
|
-- local offx = (size.x - size.x * scale)/2
|
|
-- local offy = (size.y - size.y * scale)/2
|
|
-- local to_x,to_y = x + offx,y + offy
|
|
-- local size_action = cc.SizeTo.New(time,size.x * scale , size.y * scale)
|
|
-- local move_action = cc.MoveTo.New(time,to_x , to_y)
|
|
-- return cc.Spawn.New(size_action , move_action)
|
|
-- end
|
|
|
|
cc.ScaleX = cc.ScaleX or {}
|
|
function cc.ScaleX.New(pos,size,scale,time)
|
|
local x,y = pos.x,pos.y
|
|
local offx = (size.x - size.x * scale)/2
|
|
local offy = (size.y - size.y * scale)/2
|
|
local to_x,to_y = x + offx,y
|
|
local size_action = cc.SizeTo.New(time,size.x * scale , size.y)
|
|
local move_action = cc.MoveTo.New(time,to_x ,y)
|
|
return cc.Spawn.New(size_action , move_action)
|
|
end
|
|
|
|
--[[
|
|
<*
|
|
@Author: ZensYue
|
|
@Description: 宝箱抖动效果
|
|
@param: time 运动时间
|
|
@param: node 运动节点
|
|
@param: rotation 旋转角度
|
|
@param: height 浮动高度
|
|
@param: count 运动次数
|
|
@return: action
|
|
*>
|
|
]]
|
|
cc.Shake = cc.Shake or {}
|
|
function cc.Shake.New(time ,node, rotation , height , count)
|
|
local x,y = node:GetVectorValue(WidgetProperty.Position)
|
|
local rotation_r = cc.RotateTo.New(time,rotation)
|
|
local move_up = cc.MoveTo.New(time,x,y-height)
|
|
local action_1 = cc.Spawn.New(rotation_r,move_up)
|
|
local rotation_l = cc.RotateTo.New(time,-rotation)
|
|
local move_down = cc.MoveTo.New(time,x,y+height)
|
|
local action_2 = cc.Spawn.New(rotation_l,move_down)
|
|
local action = cc.Sequence.New(action_1,action_2)
|
|
return count and cc.Repeat.New(action,count) or cc.RepeatForever.New(action)
|
|
end
|
|
|
|
cc.FlyToRandom = cc.FlyToRandom or {}
|
|
--optional里面有好几个参数可配置,不填的话就用默认的
|
|
function cc.FlyToRandom.New(start_pos, end_pos, optional)
|
|
optional = optional or {}
|
|
local min_duration = optional.min_duration or 0.5
|
|
local rand_duration = optional.rand_duration or 0.8
|
|
local duration = min_duration + math.random()*rand_duration
|
|
local stay_duration = optional.stop_duration or 0.5--飞到背包后停留多久
|
|
local is_auto_delete = optional.auto_delete or false
|
|
-- local need_flash_on_end = optional.need_flash_on_end or true--到背包后需要闪一下
|
|
--需要在开始和终点算出随机的中间点,使其成为曲线
|
|
local middlePos = GameMath.GetVecLerp(start_pos, end_pos, 0.5)
|
|
local rotate_angle = 90
|
|
local add_or_minus = math.random(1,2)
|
|
if add_or_minus <= 1 then
|
|
rotate_angle = -rotate_angle
|
|
end
|
|
local controlPos = GameMath.RotateByAngle(start_pos, middlePos, rotate_angle)
|
|
local randNum = 0.7*math.random()+0.1
|
|
controlPos = GameMath.GetVecLerp(middlePos, controlPos, randNum)
|
|
|
|
local action = cc.BezierTo.New(duration, {end_pos=end_pos,control_1=controlPos,control_2=controlPos})
|
|
-- action = cc.EaseQuadraticActionIn.New(action)
|
|
action = cc.EaseQuarticActionIn.New(action)
|
|
-- action = cc.EaseQuinticActionIn.New(action)
|
|
-- action = cc.EaseQuarticActionIn.New(action)
|
|
-- if need_flash_on_end then
|
|
-- local function on_end_callback( )
|
|
-- GlobalEventSystem:Fire(EventName.BASE_WEALTH_ADD_AFTER, "good")
|
|
-- end
|
|
-- local move_end_action = cc.CallFunc.New(on_end_callback)
|
|
-- action = cc.Sequence.New(action, move_end_action)
|
|
-- end
|
|
action = cc.Sequence.New(action, cc.DelayTime.New(stay_duration))
|
|
if is_auto_delete then
|
|
action = cc.Sequence.New(action, cc.Delete.New())
|
|
end
|
|
|
|
return action
|
|
end
|
|
|
|
cc.FlyToBgRandom = cc.FlyToBgRandom or {}
|
|
function cc.FlyToBgRandom.New(start_pos, optional)
|
|
local view_size = Game.UI:GetScreenView()
|
|
local end_pos = {x=view_size.x-177, y=view_size.y-383}--背包坐标
|
|
return cc.FlyToRandom.New(start_pos, end_pos, optional)
|
|
end
|
|
|
|
--ScrollBy start
|
|
cc.ScrollBy = cc.ScrollBy or BaseClass(cc.ActionInterval)
|
|
|
|
function cc.ScrollBy:__init(duration, delta_x,delta_y)
|
|
self:initWithDuration(duration, delta_x,delta_y)
|
|
end
|
|
|
|
function cc.ScrollBy:clone()
|
|
return cc.ScrollBy.New(self._duration, self._positionDeltaX,self._positionDeltaY)
|
|
end
|
|
|
|
function cc.ScrollBy:reverse()
|
|
return cc.ScrollBy.New(self._duration, -self._positionDeltaX,-self._positionDeltaY)
|
|
end
|
|
|
|
function cc.ScrollBy:startWithTarget(target)
|
|
cc.ActionInterval.startWithTarget(self, target)
|
|
|
|
if target.GetVectorValue then
|
|
self._previousPositionX,self._previousPositionY = target:GetVectorValue(ScrollViewProperty.CanvasPosition)
|
|
end
|
|
-- print("Cat:ActionInterval [128] self._previousPositionX,self._previousPositionY: ",self._previousPositionX,self._previousPositionY,target.GetVectorValue,target.getPositionValue,target.getPosition)
|
|
self._startPositionX,self._startPositionY = self._previousPositionX,self._previousPositionY
|
|
end
|
|
|
|
function cc.ScrollBy:update(t)
|
|
if self._target then
|
|
local currentPosX,currentPosY = 0, 0
|
|
if self._target.GetVectorValue then
|
|
currentPosX,currentPosY = self._target:GetVectorValue(ScrollViewProperty.CanvasPosition)
|
|
end
|
|
local diffX = currentPosX - self._previousPositionX
|
|
local diffY = currentPosY - self._previousPositionY
|
|
local newPosX = self._startPositionX + (self._positionDeltaX * t)
|
|
local newPosY = self._startPositionY + (self._positionDeltaY * t)
|
|
-- self._target:SetVectorValue(WidgetProperty.Position,newPosX,newPosY)
|
|
if self._target.SetVectorValue then
|
|
self._target:SetVectorValue(ScrollViewProperty.CanvasPosition, newPosX, newPosY)
|
|
end
|
|
self._previousPositionX = newPosX
|
|
self._previousPositionY = newPosY
|
|
end
|
|
end
|
|
|
|
function cc.ScrollBy:initWithDuration(duration,delta_x,delta_y)
|
|
cc.ActionInterval.initWithDuration(self,duration)
|
|
self._positionDeltaX = delta_x
|
|
self._positionDeltaY = delta_y
|
|
end
|
|
|
|
--ScrollBy end
|
|
|
|
--ScrollTo start
|
|
cc.ScrollTo = cc.ScrollTo or BaseClass(cc.ScrollBy)
|
|
function cc.ScrollTo:__init(duration, x, y)
|
|
self:initWithPos(duration, x, y)
|
|
end
|
|
|
|
function cc.ScrollTo:initWithPos(duration, x, y)
|
|
cc.ActionInterval.initWithDuration(self, duration)
|
|
self._endPositionX = x
|
|
self._endPositionY = y
|
|
end
|
|
|
|
function cc.ScrollTo:clone()
|
|
return cc.ScrollTo.New(self._duration, self._endPositionX, self._endPositionY)
|
|
end
|
|
|
|
function cc.ScrollTo:startWithTarget(target)
|
|
cc.ScrollBy.startWithTarget(self, target)
|
|
local oldX,oldY = target:GetVectorValue(ScrollViewProperty.CanvasPosition)
|
|
self._positionDeltaX = self._endPositionX - oldX
|
|
self._positionDeltaY = self._endPositionY - oldY
|
|
end
|
|
|
|
function cc.ScrollTo:reverse()
|
|
print("reverse() not supported in ScrollTo")
|
|
return nil
|
|
end
|
|
--ScrollTo end
|
|
|
|
|
|
--FontBy start
|
|
cc.FontBy = cc.FontBy or BaseClass(cc.ActionInterval)
|
|
|
|
function cc.FontBy:__init(duration, font)
|
|
self:initWithDuration(duration, font)
|
|
end
|
|
|
|
function cc.FontBy:clone()
|
|
return cc.FontBy.New(self._duration, font)
|
|
end
|
|
|
|
function cc.FontBy:reverse()
|
|
return cc.FontBy.New(self._duration, -self._positionDeltaX,-self._positionDeltaY)
|
|
end
|
|
|
|
function cc.FontBy:startWithTarget(target)
|
|
cc.ActionInterval.startWithTarget(self, target)
|
|
|
|
if target.GetInt then
|
|
self._prefont = target:GetInt(TextBoxProperty.FontSize)
|
|
end
|
|
self._start_font = self._prefont
|
|
end
|
|
|
|
function cc.FontBy:update(t)
|
|
if self._target then
|
|
local cut_font = 0
|
|
if self._target.GetInt then
|
|
cut_font = self._target:GetInt(TextBoxProperty.FontSize)
|
|
end
|
|
local new_font = self._start_font + (self._font * t)
|
|
if self._target.SetInt then
|
|
self._target:SetInt(TextBoxProperty.FontSize, new_font)
|
|
end
|
|
self._prefont = new_font
|
|
end
|
|
end
|
|
|
|
function cc.FontBy:initWithDuration(duration,font)
|
|
cc.ActionInterval.initWithDuration(self,duration)
|
|
self._font = font
|
|
end
|
|
|
|
--FontBy end
|
|
|
|
--FontTo start
|
|
cc.FontTo = cc.FontTo or BaseClass(cc.FontBy)
|
|
function cc.FontTo:__init(duration, font)
|
|
self:initWithFont(duration, font)
|
|
end
|
|
|
|
function cc.FontTo:initWithFont(duration, font)
|
|
cc.ActionInterval.initWithDuration(self, duration)
|
|
self._end_font = font
|
|
end
|
|
|
|
function cc.FontTo:clone()
|
|
return cc.FontTo.New(duration, font)
|
|
end
|
|
|
|
function cc.FontTo:startWithTarget(target)
|
|
cc.FontBy.startWithTarget(self, target)
|
|
|
|
local old_font = target:GetInt(TextBoxProperty.FontSize)
|
|
self._font = self._end_font - old_font
|
|
end
|
|
|
|
function cc.FontTo:reverse()
|
|
print("reverse() not supported in FontTo")
|
|
return nil
|
|
end
|
|
--FontTo end
|
|
|
|
cc.FontToAction = cc.FontToAction or {}
|
|
function cc.FontToAction.New(pos,cur_font,font,time)
|
|
local x,y = pos.x,pos.y
|
|
local offx = (cur_font - font)
|
|
local offy = (cur_font - font)
|
|
local to_x,to_y = x + offx,y + offy
|
|
local size_action = cc.FontTo.New(time,font)
|
|
local move_action = cc.MoveTo.New(time,to_x , to_y)
|
|
return cc.Spawn.New(size_action , move_action)
|
|
end
|
|
|
|
--[[
|
|
Author:LZR
|
|
Description:短距离滑入动画
|
|
parameters
|
|
[1] = 时间
|
|
[2] = 节点
|
|
[3] = 移动方式
|
|
[4] = 偏移值
|
|
]]
|
|
--no_back--不回去
|
|
--SweepAction start
|
|
cc.SweepAction = cc.SweepAction or {}
|
|
function cc.SweepAction.New(time,transform,move_type,offset,no_back,fadein)
|
|
time = time or 1
|
|
offset = offset or 100
|
|
move_type = move_type or "down"
|
|
local pos = {}
|
|
pos.x,pos.y = GetAnchoredPosition(transform)
|
|
local start_x,start_y = pos.x,pos.y
|
|
local end_x,end_y = pos.x,pos.y
|
|
if not no_back then--回去(设置偏移offset的坐标再动画移动回到原点)
|
|
if move_type == "down" then
|
|
start_y = start_y - offset
|
|
elseif move_type == "up" then
|
|
start_y = start_y + offset
|
|
elseif move_type == "left" then
|
|
start_x = start_x + offset
|
|
else
|
|
start_x = start_x - offset
|
|
end
|
|
SetAnchoredPosition(transform,start_x,start_y)
|
|
else----不回去(动画移动偏移offset的坐标)
|
|
if move_type == "down" then
|
|
end_y = end_y - offset
|
|
elseif move_type == "up" then
|
|
end_y = end_y + offset
|
|
elseif move_type == "left" then
|
|
end_x = end_x - offset
|
|
else
|
|
end_x = end_x + offset
|
|
end
|
|
-- print("huangcong:ActionExtend [start:429] :",pos.x, end_x, move_type)
|
|
end
|
|
|
|
local action = cc.MoveTo.createAnchoredType(time,end_x,end_y)
|
|
-- if fadein then--同时执行透明和位置移动
|
|
-- local fade_action = cc.FadeTo.New(time,1,true)
|
|
-- action = cc.Spawn.New(action,fade_action)
|
|
-- end
|
|
local elastic_in_time = 3
|
|
local elastic_out_time = 5
|
|
action = cc.EaseElasticIn.New(action,elastic_in_time)
|
|
action = cc.EaseElasticOut.New(action,elastic_out_time)
|
|
local call_func = cc.CallFunc.New(cc.ActionManager:getInstance():removeAllActionsFromTarget(transform))
|
|
action = cc.Sequence.New(action, call_func)
|
|
return action
|
|
end
|
|
--SweepAction end
|
|
|
|
--[[
|
|
Author:LZR
|
|
Description:虎躯一震(心跳效果)
|
|
parameters
|
|
[1] = 时间
|
|
[2] = 对象
|
|
[3] = 延迟时间
|
|
[3] = 收缩比例
|
|
[4] = 放大比例
|
|
[5] = 行为时间比例{收缩时长,放大时长,复原时长}
|
|
]]
|
|
--HeartBeat start
|
|
cc.HeartBeat = cc.HeartBeat or {}
|
|
function cc.HeartBeat.New(time,obj,delay_time,scaleInfo1,scaleInfo2,time_auto)
|
|
if obj == nil then return end
|
|
delay_time = delay_time or 0
|
|
time = time or 1
|
|
scaleInfo = scaleInfo or 0.9
|
|
scaleInfo2 = scaleInfo2 or 1.1
|
|
time_auto = time_auto or {30,20,40}
|
|
local scaleNum = scaleInfo
|
|
local x,y = obj:GetVectorValue(WidgetProperty.Position)
|
|
local sx,sy = obj:GetVectorValue(WidgetProperty.Size)
|
|
|
|
local function getmovepos(scale)
|
|
local _sx,_sy = obj:GetVectorValue(WidgetProperty.Size)
|
|
local new_sx,new_sy = _sx * scale, _sy * scale
|
|
local mx,my = (_sx - new_sx)/2, (_sy - new_sy)/2
|
|
return mx,my
|
|
end
|
|
local action1,action2,action3
|
|
local action1_1 = cc.SizeTo.New(time*(time_auto[1]/100), sx*scaleNum,sy*scaleNum)
|
|
local _x,_y = getmovepos(scaleNum)
|
|
local action1_2 = cc.MoveTo.New(time*(time_auto[1]/100), x+_x,y+_y)
|
|
action1 = cc.Spawn.New(action1_1, action1_2)
|
|
action1 = cc.EaseSineIn.New(action1)
|
|
|
|
scaleNum2 = (1/scaleInfo * scaleInfo2)
|
|
local action2_1 = cc.SizeTo.New(time*(time_auto[2]/100), sx*scaleNum2,sy*scaleNum2)
|
|
_x,_y = getmovepos(scaleNum2)
|
|
local action2_2 = cc.MoveTo.New(time*(time_auto[2]/100), x+_x,y+_y )
|
|
action2 = cc.Spawn.New(action2_1, action2_2)
|
|
action2 = cc.EaseSineOut.New(action2)
|
|
|
|
scaleNum3 = (1/(1/scaleInfo * scaleInfo2))
|
|
local action_3_1 = cc.SizeTo.New(time*(time_auto[3]/100), sx,sy)
|
|
local action_3_2 = cc.MoveTo.New(time*(time_auto[3]/100), x,y)
|
|
action3 = cc.Spawn.New(action_3_1, action_3_2)
|
|
action3 = cc.EaseSineOut.New(action3)
|
|
|
|
local action = cc.Sequence.New(cc.DelayTime.New(delay_time),action1, action2, action3)
|
|
return action
|
|
end
|
|
|
|
|
|
--[[
|
|
Author:huangcong
|
|
Description:重物掉落震动 节点需要挂载CanvasGroup(以便遍历子节点的透明度)
|
|
parameters
|
|
data.transform--节点
|
|
data.delay_time or 0.8--时间
|
|
data.init_scale or 2--初始大小
|
|
data.end_scale or 1--结束大小
|
|
data.start_pos or {x = -200,y = -50}--初始坐标
|
|
data.end_pos or {x = -200,y = -50}--结束坐标
|
|
data.init_alpha or 0--初始透明度
|
|
data.end_alpha or 0--初始透明度
|
|
]]
|
|
--HeartBeat start
|
|
cc.FallingVibration = cc.FallingVibration or {}
|
|
function cc.FallingVibration.New(data)
|
|
if data == nil or data.transform == nil then return end
|
|
local transform = data.transform--节点
|
|
local delay_time = data.delay_time or 0.8--时间
|
|
local init_scale = data.init_scale or 2--初始大小
|
|
local end_scale = data.end_scale or 1--结束大小
|
|
local start_pos = data.start_pos or {x = -200,y = -50}--初始坐标
|
|
local end_pos = data.end_pos or {x = -200,y = -50}--结束坐标
|
|
local init_alpha = data.init_alpha or 0--初始透明度
|
|
local end_alpha = data.end_alpha or 1--初始透明度
|
|
|
|
transform:GetComponent("CanvasGroup").alpha = init_alpha
|
|
transform.localScale = Vector3(init_scale,init_scale,init_scale)
|
|
SetAnchoredPosition(transform,start_pos.x,start_pos.y)
|
|
local function alphaChangeFunc( percent )
|
|
transform:GetComponent("CanvasGroup").alpha = percent*end_alpha
|
|
end
|
|
--设置透明度变化
|
|
local alpha_action = cc.CustomUpdate.New(delay_time,alphaChangeFunc)
|
|
|
|
--设置大小变化
|
|
local scale_action = cc.ScaleTo.New(delay_time,end_scale,end_scale,end_scale)
|
|
|
|
--设置移动方式
|
|
local move_action = cc.MoveTo.createAnchoredType(delay_time,end_pos.x,end_pos.y)
|
|
local elastic_in_time = 5
|
|
local elastic_out_time = 5
|
|
move_action = cc.EaseElasticIn.New(move_action,elastic_in_time)--缓动1
|
|
-- move_action = cc.EaseElasticOut.New(move_action,elastic_out_time)--缓动2
|
|
|
|
--合并动画列表
|
|
local action_list = cc.Spawn.New(alpha_action,scale_action)--同时执行三个动作
|
|
action_list = cc.Spawn.New(action_list,move_action)--同时执行三个动作
|
|
|
|
local function end_func( ... )
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(transform)
|
|
if data.end_call_func then
|
|
data.end_call_func()
|
|
end
|
|
end
|
|
local call_func = cc.CallFunc.New(end_func)
|
|
action_list = cc.Sequence.New(action_list, call_func)
|
|
return action_list
|
|
end
|
|
|
|
--HeartBeat end
|
|
--Ellipse 椭圆运动
|
|
cc.Ellipse = cc.Ellipse or BaseClass(cc.ActionInterval)
|
|
function cc.Ellipse:__init(config)
|
|
self.config = config
|
|
self:initWithDuration(config.time)
|
|
end
|
|
|
|
function cc.Ellipse:clone()
|
|
return cc.Ellipse.New(self.config)
|
|
end
|
|
|
|
function cc.Ellipse:reverse()
|
|
self.config.moveInAnticlockwise = not self.config.moveInAnticlockwise
|
|
return cc.Ellipse.New(self.config)
|
|
end
|
|
|
|
function cc.Ellipse:startWithTarget(target)
|
|
cc.ActionInterval.startWithTarget(self, target)
|
|
end
|
|
|
|
function cc.Ellipse:update(t)
|
|
if self._target then
|
|
local p = self._target.ellipse_p or 0
|
|
local x = self.config:GetPositionXAtOval(t + p)
|
|
local y = self.config:GetPositionYAtOval(t + p)
|
|
cc.Wrapper.SetLocalPosition(self._target,x,y)
|
|
end
|
|
end
|
|
|
|
function cc.Ellipse:initWithDuration(duration)
|
|
cc.ActionInterval.initWithDuration(self,duration)
|
|
end
|
|
|
|
cc.SliderAction = cc.SliderAction or {}
|
|
--duration*时间
|
|
--target*进度条对象
|
|
--num*需要变化的值
|
|
--sum_num*值的总数
|
|
function cc.SliderAction.New(duration, target, num, sum_num)
|
|
local speed = num/duration
|
|
local delay_time = 0.1
|
|
local time_sum = 0
|
|
local function change_value( ... )--变化方法
|
|
time_sum = time_sum + delay_time
|
|
local cur_num = speed * (time_sum + delay_time)
|
|
target.value = cur_num/ sum_num
|
|
if cur_num >= num then
|
|
target.value = num / sum_num
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(target)
|
|
end
|
|
end
|
|
|
|
local action = cc.DelayTime.New(delay_time)--每次加一次 延迟一次
|
|
action = cc.Sequence.New(cc.CallFunc.New(change_value),cc.DelayTime.New(delay_time))
|
|
cc.ActionManager:getInstance():addAction(cc.RepeatForever.New(action), target)
|
|
end
|
|
|
|
|
|
cc.SliderBy = cc.SliderBy or BaseClass(cc.ActionInterval)--图片进度条增长动画
|
|
|
|
--duration*时间
|
|
--deltaNum*比例系数
|
|
--isInteger表示数字是否以整数改变
|
|
function cc.SliderBy:__init(duration, deltaNum, sum_num,cur_num)
|
|
self:initWithDuration(duration, deltaNum,sum_num,cur_num)
|
|
end
|
|
|
|
function cc.SliderBy:initWithDuration(duration, deltaNum,sum_num,cur_num)
|
|
cc.ActionInterval.initWithDuration(self, duration)
|
|
self.deltaNum = deltaNum
|
|
self.sum_num = sum_num or 1
|
|
self.cur_num = cur_num or 0
|
|
end
|
|
|
|
function cc.SliderBy:clone()
|
|
return cc.SliderBy.New(self._duration, self.deltaNum, self.sum_num, self.cur_num)
|
|
end
|
|
|
|
function cc.SliderBy:startWithTarget(target)
|
|
cc.ActionInterval.startWithTarget(self, target)
|
|
self.previousNum = self.cur_num
|
|
end
|
|
|
|
function cc.SliderBy:reverse()
|
|
return cc.SliderBy.New(self._duration, -self.deltaNum, self.sum_num, self.cur_num)
|
|
end
|
|
|
|
function cc.SliderBy:update(t)
|
|
if (self._target) then
|
|
local newNum = self.previousNum + (self.deltaNum * t) * (self.sum_num)
|
|
SetSizeDeltaX(self._target,newNum)
|
|
end
|
|
end
|
|
|
|
cc.SliderTextBy = cc.SliderTextBy or BaseClass(cc.ActionInterval)--字体增长动画
|
|
|
|
--duration*时间
|
|
--cur_num*变化初始值 假设为10
|
|
--anim_num*变化值 假设为90(最终值就是100)
|
|
--add_str*添加字符串 默认为"%s" --后面要用到string.format()这样可以支持更多格式 比如变化一个“当前VIP经验+%s”
|
|
function cc.SliderTextBy:__init(duration,cur_num,anim_num,add_str)
|
|
self:initWithDuration(duration, cur_num, anim_num, add_str)
|
|
end
|
|
|
|
function cc.SliderTextBy:initWithDuration(duration, cur_num, anim_num, add_str)
|
|
cc.ActionInterval.initWithDuration(self, duration)
|
|
self.add_str = add_str or "%s"
|
|
self.anim_num = anim_num or 0
|
|
self.cur_num = cur_num or 0
|
|
end
|
|
|
|
function cc.SliderTextBy:clone()
|
|
return cc.SliderTextBy.New(self._duration, self.cur_num, self.anim_num, self.add_str)
|
|
end
|
|
|
|
function cc.SliderTextBy:startWithTarget(target)
|
|
cc.ActionInterval.startWithTarget(self, target)
|
|
self.previousNum = self.cur_num
|
|
end
|
|
|
|
function cc.SliderTextBy:reverse()
|
|
return cc.SliderTextBy.New(self._duration, self.cur_num, -self.anim_num, self.add_str)
|
|
end
|
|
|
|
function cc.SliderTextBy:update(t)
|
|
if (self._target) then
|
|
local newNum = self.previousNum + (self.anim_num * t)
|
|
newNum = math.floor(newNum)
|
|
self._target.text = string.format(self.add_str,newNum)
|
|
end
|
|
end
|
|
|
|
cc.SliderByNew = cc.SliderByNew or BaseClass(cc.ActionInterval)--图片进度条增长动画(区别于另一种 使用fillamout)
|
|
|
|
--duration*时间
|
|
--cur_num当前值
|
|
--end_num结束值
|
|
--sum_num总值
|
|
--必须传入image组件(imageEx没试过 你们可以试试)
|
|
function cc.SliderByNew:__init(duration, cur_num, end_num, sum_num)
|
|
self:initWithDuration(duration, cur_num, end_num, sum_num)
|
|
end
|
|
|
|
function cc.SliderByNew.createSizeType(duration, cur_num, end_num, sum_num)
|
|
local action = cc.SliderByNew.New(duration, cur_num, end_num, sum_num)
|
|
action.set_size_type = true
|
|
return action
|
|
end
|
|
|
|
function cc.SliderByNew:initWithDuration(duration, cur_num, end_num, sum_num)
|
|
cc.ActionInterval.initWithDuration(self, duration)
|
|
self.sum_num = sum_num or 1
|
|
self.cur_num = cur_num or 0
|
|
self.end_num = end_num or 0
|
|
end
|
|
|
|
function cc.SliderByNew:clone()
|
|
return cc.SliderByNew.New(self._duration, self.cur_num, self.end_num, self.sum_num)
|
|
end
|
|
|
|
function cc.SliderByNew:startWithTarget(target)
|
|
cc.ActionInterval.startWithTarget(self, target)
|
|
self.previousNum = self.cur_num
|
|
end
|
|
|
|
function cc.SliderByNew:reverse()
|
|
return cc.SliderByNew.New(self._duration, self.end_num, self.cur_num, self.sum_num)
|
|
end
|
|
|
|
function cc.SliderByNew:update(t)
|
|
if (self._target) then
|
|
local newNum = self.previousNum + t * (self.end_num- self.cur_num)
|
|
if self.set_size_type then
|
|
SetSizeDeltaX(self._target, newNum)
|
|
else
|
|
self._target.fillAmount = newNum / self.sum_num
|
|
end
|
|
end
|
|
end
|
|
|
|
--ChangeImage start
|
|
cc.ChangeImage = cc.ChangeImage or BaseClass(cc.ActionInstant)
|
|
|
|
function cc.ChangeImage:__init( image_info )
|
|
self.image_info = image_info
|
|
end
|
|
|
|
function cc.ChangeImage:clone()
|
|
return cc.ChangeImage.New(self.image_info)
|
|
end
|
|
|
|
function cc.ChangeImage:reverse()
|
|
return self:clone()
|
|
end
|
|
|
|
function cc.ChangeImage:update(time)
|
|
if not self._target then return end
|
|
lua_resM:setImageSprite(self.image_info.arge_self, self.image_info.image or self._target, self.image_info.abName, self.image_info.resName, self.image_info.auto_size, self.image_info.load_call_back)
|
|
end
|
|
--Alpha end
|
|
|
|
--DestroyObject start
|
|
cc.DestroyObject = cc.DestroyObject or BaseClass(cc.ActionInstant)
|
|
|
|
function cc.DestroyObject:__init()
|
|
end
|
|
|
|
function cc.DestroyObject:clone()
|
|
return cc.DestroyObject.New()
|
|
end
|
|
|
|
function cc.DestroyObject:update(time)
|
|
cc.Wrapper.DestroyObject(self._target)
|
|
end
|
|
--DestroyObject end
|
|
|
|
--CustomUpdate start
|
|
cc.CustomUpdate = cc.CustomUpdate or BaseClass(cc.ActionInterval)
|
|
--别用.New了,用create前缀的接口
|
|
function cc.CustomUpdate:__init(duration, call_back)
|
|
self:init(duration, call_back)
|
|
end
|
|
|
|
function cc.CustomUpdate:init(duration, call_back)
|
|
cc.ActionInterval.initWithDuration(self, duration)
|
|
self._call_back = call_back
|
|
end
|
|
|
|
function cc.CustomUpdate:clone()
|
|
local action = cc.CustomUpdate.New()
|
|
action:init(self._duration, self._call_back)
|
|
return action
|
|
end
|
|
|
|
function cc.CustomUpdate:reverse()
|
|
return nil
|
|
end
|
|
|
|
function cc.CustomUpdate:startWithTarget(target)
|
|
cc.ActionInterval.startWithTarget(self, target)
|
|
end
|
|
|
|
function cc.CustomUpdate:update(t)
|
|
if self._call_back then
|
|
self._call_back(t)
|
|
end
|
|
end
|
|
--CustomUpdate end
|
|
|