--本API主要是显示拉光效果
function GameScene:ShowClip(conf)
-- body
local target = conf.target --要扫描的对象
local targetFilePath = conf.targetFilePath or "" --要扫描对象纹理图片
local lightPicPath = conf.lightPicPath or "upgrade_icon_white.png" --扫描图片路径
local isLoop = conf.isLoop ~= nil and conf.isLoop or false --是否循环扫描
local speed = conf.speed or 150 --扫描速度
local size = target:getContentSize()
local m_clip = cc.LayerColor:create(cc.c4f(0,0,0,0),size.width,size.height) --可控制扫描的暗影
local m_clipping = cc.ClippingNode:create() --镂空node
-- 设置一些属性
m_clipping:setInverted(false)
m_clipping:setAlphaThreshold(0)
m_clipping:addChild(m_clip)
--创建扫描对象的像素副本
local m_sp = cc.Sprite:create(targetFilePath, cc.rect(0, 0, size.width, size.height))
m_sp:setAnchorPoint(cc.p(0,0))
m_clipping:setStencil(m_sp)
--创建扫描拉光
local m_light = cc.Sprite:create(lightPicPath)
--设置扫光图片的相关属性(根据需求设置)
m_light:setScaleX(0.4)
-- m_light:setRotation(-50)
m_light:setOpacity(150)
m_light:setPositionX(-size.width)
m_clipping:addChild(m_light)
local time = (size.width * 2) / speed
local actArray = {}
local pMoveBy = cc.MoveBy:create(time, cc.p(size.width * 2, 0))
local pHide = cc.Hide:create()
local callFunc = cc.CallFunc:create(function (pSender)
pSender:setPositionX(-size.width)
end)
local delayTime = cc.DelayTime:create(0.25)
local pHideReverse = pHide:reverse()
table.insert(actArray,pMoveBy)
table.insert(actArray,pHide)
table.insert(actArray,callFunc)
table.insert(actArray,delayTime)
table.insert(actArray,pHideReverse)
local pSequence = cc.Sequence:create(actArray)
if isLoop then
m_light:runAction(cc.RepeatForever:create(pSequence))
else
m_light:runAction(pSequence)
m_clipping:runAction(cc.Sequence:create(cc.DelayTime:create(time), cc.RemoveSelf:create()))
end
target:addChild(m_clipping)
end