--放大动作 有回弹
function CommonFunc.scaleAction(node, startScale, time, cb)
local p = 1
startScale = startScale or 0.4
time = time or 0.2
node:setScale(startScale)
node:runAction(cc.Sequence:create( cc.ScaleTo:create( 0.2 ,p + 0.05),
cc.ScaleTo:create(0.15,p),
cc.CallFunc:create(function()
if cb and type(cb) == "function" then
cb()
end
end)))
end
--放大动作 无回弹
function CommonFunc.scaleAction2(node, startScale, time,cb)
local p = 1
startScale = startScale or 0.4
node:setScale(startScale)
node:runAction(cc.Sequence:create( cc.ScaleTo:create(time or 0.15, p),
cc.CallFunc:create(function()
if cb and type(cb) == "function" then
cb()
end
end)))
end
--回弹移动动作
function CommonFunc.moveAction(node, distanceX, distanceY, time, isSpringBack, cb)
distanceX = distanceX or 0
distanceY = distanceY or 0
time = time or 0.2
isSpringBack = isSpringBack or false
local x,y = node:getPosition()
local function func()
if isSpringBack then
local x2,y2
local SpringBackNum = 40
if distanceX ~= 0 then
if distanceX < 0 then
x2 = x - SpringBackNum
else
x2 = x + SpringBackNum
end
else
x2 = x
end
if distanceY ~= 0 then
if distanceY < 0 then
y2 = y - SpringBackNum
else
y2 = y + SpringBackNum
end
else
y2 = y
end
node:runAction(cc.Sequence:create( cc.MoveTo:create(0.1,cc.p(x2,y2)),
cc.MoveTo:create(0.1,cc.p(x,y)),
cc.CallFunc:create(function()
if cb and type(cb) == "function" then
cb()
end
end)))
end
end
node:setPosition(x + distanceX, y + distanceY)
node:runAction(cc.Sequence:create(cc.MoveTo:create(time, cc.p(x,y)), cc.CallFunc:create(function()
func()
end)))
end
--缓冲动作(移过头之后回去)
function CommonFunc.bufferAction(node, distanceX, distanceY,time,cb)
distanceX = distanceX or 0
distanceY = distanceY or 0
local x,y = node:getPosition()
local x2, y2
if distanceX ~= 0 then
if distanceX < 0 then
x2 = x - 30
else
x2 = x + 30
end
else
x2 = x
end
if distanceY ~= 0 then
if distanceY < 0 then
y2 = y + 30
else
y2 = y - 30
end
else
y2 = y
end
node:setPosition(x + distanceX, y + distanceY)
node:runAction(cc.Sequence:create( cc.MoveTo:create(0.2,cc.p(x2,y2)),
cc.MoveTo:create(0.2,cc.p(x,y)),
cc.CallFunc:create(function()
if cb and type(cb) == "function" then
cb()
end
end)))
end
--逐渐出现动作
function CommonFunc.runFadeInAction(node, distanceX, distanceY, time,cb)
distanceX = distanceX or 0
distanceY = distanceY or 0
time = time or 0.3
local x,y = node:getPosition()
local x2, y2
node:setPosition(cc.p(x + distanceX, y + distanceY))
node:setOpacity(0)
node:runAction(cc.FadeTo:create(time,255))
node:runAction(cc.Spawn:create(cc.FadeTo :create(time,255),
cc.Sequence:create( cc.MoveTo:create(time,cc.p(x,y)),
cc.CallFunc:create(function()
if cb and type(cb) == "function" then
cb()
end
end))))
end
function CommonFunc.runFadeInActionWithPosition(node,x,y,distanceX,distanceY,time,cb)
local time = time or 0.3
local x2, y2
node:setPosition(cc.p(x + distanceX, y + distanceY))
node:setOpacity(0)
node:runAction(cc.FadeTo:create(time,255))
node:runAction(cc.Spawn:create(cc.FadeTo :create(time,255),
cc.Sequence:create( cc.MoveTo:create(time,cc.p(x,y)),
cc.CallFunc:create(function()
if cb and type(cb) == "function" then
cb()
end
end))))
end
--逐渐消失动作
function CommonFunc.runFadeOutAction(node, distanceX, distanceY, time, cb)
distanceX = distanceX or 0
distanceY = distanceY or 0
time = time or 0.3
local x,y = node:getPosition()
local x2, y2 = x + distanceX, y + distanceY
node:runAction(cc.Spawn:create( cc.FadeTo :create(time, 0),
cc.Sequence:create( cc.MoveTo :create(time,cc.p(x2, y2)),
cc.CallFunc:create(function()
if cb and type(cb) == "function" then
cb()
end
end))))
end