demo下载:Quick-x-HighlightArea-master.zip
1、混合模式
@H_502_15@ (1)首先创建一个全屏的CCRenderTexture实例 @H_502_15@ 这里使用的黑色 0.6的透明度,看起来的效果就是一层黑色半透明的遮罩叠在游戏界面上面:
1
2
3
4
|
localpRt=CCRenderTexture:create(size.width,size.height)
localcolor=ccc3(0,0)--黑色
localopacity=0.6--透明度
pRt:clear(color.r,color.g,color.b,opacity)
|
@H_502_15@ (2)设置混合模式 @H_502_15@ 具体原理可以参考http://www.jb51.cc/article/p-xfoespbu-xd.html
localblend=ccBlendFunc()
blend.src=GL_ZERO
blend.dst=GL_ONE_MINUS_SRC_ALPHA
|
localcircleSpr=CCSprite:create(
"Images/circle.png"
)
localcircleSize=circleSpr:getContentSize()
circleSpr:setBlendFunc(blend)--把贴图“刷”掉,高亮效果的关键
--宽度和高度参数,1.4142为根号2,矩形的外接椭圆的长轴与短轴长度
localwidthPara=1.4142/circleSize.width
localheightPara=1.4142/circleSize.height
localrectArray={[1]=CCRect(100,100,100),
[2]=CCRect(200,150),
[3]=CCRect(450,35,150,
[4]=CCRect(300,300,
}
pRt:begin()
for
i,rectinipairs(rectArray)
do
localfScaleX=widthPara*rect.size.width
localfScaleY=heightPara*rect.size.height
circleSpr:setScaleX(fScaleX)
circleSpr:setScaleY(fScaleY)
circleSpr:setPosition(rect:getMidX(),rect:getMidY())
circleSpr:visit()
end
pRt:endToLua()
|
localnewSprite=CCSprite:createWithTexture(pRt:getSprite():getTexture())
newSprite:setFlipY(
true
)--翻转
newSprite:setPosition(display.cx,display.cy)
self:addChild(newSprite)
|